forked from thompsonsj/slate-serializers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.ts
39 lines (38 loc) · 1.18 KB
/
default.ts
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
import { getAttributeValue } from 'domutils'
import { HtmlToSlateConfig } from '../../'
export const config: HtmlToSlateConfig = {
elementStyleMap: {
align: 'textAlign',
},
elementTags: {
a: (el) => ({
type: 'link',
newTab: el && getAttributeValue(el, 'target') === '_blank',
url: el && getAttributeValue(el, 'href'),
}),
blockquote: () => ({ type: 'blockquote' }),
h1: () => ({ type: 'h1' }),
h2: () => ({ type: 'h2' }),
h3: () => ({ type: 'h3' }),
h4: () => ({ type: 'h4' }),
h5: () => ({ type: 'h5' }),
h6: () => ({ type: 'h6' }),
li: () => ({ type: 'li' }),
ol: () => ({ type: 'ol' }),
p: () => ({ type: 'p' }),
ul: () => ({ type: 'ul' }),
},
textTags: {
code: () => ({ code: true }),
pre: () => ({ code: true }),
del: () => ({ strikethrough: true }),
em: () => ({ italic: true }),
i: () => ({ italic: true }),
s: () => ({ strikethrough: true }),
strong: () => ({ bold: true }),
u: () => ({ underline: true }),
},
htmlPreProcessString: (html) => html.replace(/<pre[^>]*>/g, '<code>').replace(/<\/pre>/g, '</code>'),
filterWhitespaceNodes: true,
convertBrToLineBreak: true,
}