-
Notifications
You must be signed in to change notification settings - Fork 153
/
schema.ts
243 lines (216 loc) · 4.37 KB
/
schema.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import type { Schema } from './types';
import Tag from './tag';
export const document: Schema = {
render: 'article',
children: [
'heading',
'paragraph',
'image',
'table',
'tag',
'fence',
'blockquote',
'comment',
'list',
'hr',
],
attributes: {
frontmatter: { render: false },
},
};
export const heading: Schema = {
children: ['inline'],
attributes: {
level: { type: Number, render: false, required: true },
},
transform(node, config) {
return new Tag(
`h${node.attributes['level']}`,
node.transformAttributes(config),
node.transformChildren(config)
);
},
};
export const paragraph: Schema = {
render: 'p',
children: ['inline'],
};
export const image: Schema = {
render: 'img',
attributes: {
src: { type: String, required: true },
alt: { type: String },
title: { type: String },
// width/height attributes will need to be to be implemented as an extension to markdown-it
},
};
export const fence: Schema = {
render: 'pre',
attributes: {
content: { type: String, render: false, required: true },
language: { type: String, render: 'data-language' },
process: { type: Boolean, render: false, default: true },
},
transform(node, config) {
const attributes = node.transformAttributes(config);
const children = node.children.length
? node.transformChildren(config)
: [node.attributes.content];
return new Tag('pre', attributes, children);
},
};
export const blockquote: Schema = {
render: 'blockquote',
children: [
'heading',
'paragraph',
'image',
'table',
'tag',
'fence',
'blockquote',
'list',
'hr',
],
};
export const item: Schema = {
render: 'li',
children: [
'inline',
'heading',
'paragraph',
'image',
'table',
'tag',
'fence',
'blockquote',
'list',
'hr',
],
};
export const list: Schema = {
children: ['item'],
attributes: {
ordered: { type: Boolean, render: false, required: true },
},
transform(node, config) {
return new Tag(
node.attributes.ordered ? 'ol' : 'ul',
node.transformAttributes(config),
node.transformChildren(config)
);
},
};
export const hr: Schema = {
render: 'hr',
};
export const table: Schema = {
render: 'table',
};
export const td: Schema = {
render: 'td',
children: [
'inline',
'heading',
'paragraph',
'image',
'table',
'tag',
'fence',
'blockquote',
'list',
'hr',
],
attributes: {
colspan: { type: Number },
rowspan: { type: Number },
align: { type: String },
},
};
export const th: Schema = {
render: 'th',
attributes: {
width: { type: Number },
align: { type: String },
},
};
export const tr: Schema = {
render: 'tr',
children: ['th', 'td'],
};
export const tbody: Schema = {
render: 'tbody',
children: ['tr', 'tag'],
};
export const thead: Schema = {
render: 'thead',
children: ['tr'],
};
export const strong: Schema = {
render: 'strong',
children: ['em', 's', 'link', 'code', 'text', 'tag'],
};
export const em: Schema = {
render: 'em',
children: ['strong', 's', 'link', 'code', 'text', 'tag'],
};
export const s: Schema = {
render: 's',
children: ['strong', 'em', 'link', 'code', 'text', 'tag'],
};
export const inline: Schema = {
children: [
'strong',
'em',
's',
'code',
'text',
'tag',
'link',
'image',
'hardbreak',
'softbreak',
'comment',
],
};
export const link: Schema = {
render: 'a',
children: ['strong', 'em', 's', 'code', 'text', 'tag'],
attributes: {
href: { type: String, required: true },
title: { type: String },
},
};
export const code: Schema = {
render: 'code',
attributes: {
content: { type: String, render: false, required: true },
},
transform(node, config) {
const attributes = node.transformAttributes(config);
return new Tag('code', attributes, [node.attributes.content]);
},
};
export const text: Schema = {
attributes: {
content: { type: String, required: true },
},
transform(node) {
return node.attributes.content;
},
};
export const hardbreak: Schema = {
render: 'br',
};
export const softbreak: Schema = {
transform() {
return ' ';
},
};
export const comment = {
attributes: {
content: { type: String, required: true },
},
};
export const error = {};
export const node = {};