-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslice.js
73 lines (56 loc) · 1.78 KB
/
slice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { createSlice } from "@reduxjs/toolkit";
import { marked } from "marked";
const initialText = `# About Me
---
## *I am* Abdullah Fatota
- *Software Engineer*
## Some of my projects
1. **Work Break timer** [Live App](https://new-af.github.io/) \[[GitHub Repository](https://github.com/new-AF/react-redux-work-break-timer)\]
2. **Product Page** [Live Page](https://new-af.github.io/)
## Images of live apps
1. 
2. 
## Code
### Inline Code
This Inline code defines a function \`add\` on a single line as \`const add = (a,b)=> a+b;\`
### Code Block
\`\`\`javascript
const add = (a, b) => {
const result = a + b;
return result;
}
\`\`\`
## Block quote
> This is a block quote
`;
//pass optional test, convert line breaks to <br> and
//set highlighter.
marked.setOptions({ gfm: true, breaks: true });
marked.setOptions({
highlight: (text, userLang) => {
const lang = Prism.languages.hasOwnProperty(userLang)
? userLang
: "plaintext";
const result = Prism.highlight(text, Prism.languages[lang], lang);
// console.info({ result, userLang });
return result;
},
});
/* Edit state */
const initialState = {
input: initialText,
output: marked.parse(initialText),
};
const slice = createSlice({
name: "text-slice",
initialState: initialState,
reducers: {
setInput: (state, action) => {
const text = action.payload;
state.input = text;
state.output = marked.parse(text);
},
},
});
export const { setInput } = slice.actions;
export default slice.reducer;