forked from thompsonsj/slate-serializers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.ts
56 lines (53 loc) · 1.17 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Element } from 'domhandler'
import { Config } from './types'
// Map Slate element names to HTML tag names
// Staightforward transform - no attributes are considered
// Use transforms instead for more complex operations
const ELEMENT_NAME_TAG_MAP = {
p: 'p',
paragraph: 'p',
h1: 'h1',
h2: 'h2',
h3: 'h3',
h4: 'h4',
h5: 'h5',
h6: 'h6',
ul: 'ul',
ol: 'ol',
li: 'li',
blockquote: 'blockquote',
}
const MARK_ELEMENT_TAG_MAP = {
strikethrough: ['s'],
bold: ['strong'],
underline: ['u'],
italic: ['i'],
code: ['pre', 'code'],
}
export const config: Config = {
markMap: MARK_ELEMENT_TAG_MAP,
elementMap: ELEMENT_NAME_TAG_MAP,
elementTransforms: {
quote: ({ children = [] }) => {
const p = [new Element('p', {}, children)]
return new Element('blockquote', {}, p)
},
link: ({ node, children = [] }) => {
const attrs: any = {}
if (node.newTab) {
attrs.target = '_blank'
}
return new Element(
'a',
{
href: node.url,
...attrs,
},
children,
)
},
},
encodeEntities: true,
alwaysEncodeCodeEntities: false,
convertLineBreakToBr: false,
}