@milkdown/preset-gfm 7.5.0 → 7.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__internal__/with-meta.d.ts.map +1 -1
- package/lib/composed/commands.d.ts +7 -7
- package/lib/composed/commands.d.ts.map +1 -1
- package/lib/composed/inputrules.d.ts.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +407 -323
- package/lib/index.es.js.map +1 -1
- package/lib/mark/strike-through.d.ts.map +1 -1
- package/lib/node/footnote/definition.d.ts.map +1 -1
- package/lib/node/footnote/reference.d.ts.map +1 -1
- package/lib/node/table/command.d.ts +11 -11
- package/lib/node/table/command.d.ts.map +1 -1
- package/lib/node/table/input.d.ts.map +1 -1
- package/lib/node/table/schema.d.ts.map +1 -1
- package/lib/node/table/utils.d.ts.map +1 -1
- package/lib/node/task-list-item.d.ts.map +1 -1
- package/lib/plugin/keep-table-align-plugin.d.ts.map +1 -1
- package/lib/plugin/remark-gfm-plugin.d.ts.map +1 -1
- package/lib/plugin/table-editing-plugin.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/__internal__/with-meta.ts +4 -1
- package/src/composed/commands.ts +17 -1
- package/src/composed/inputrules.ts +1 -3
- package/src/index.ts +16 -2
- package/src/mark/strike-through.ts +21 -9
- package/src/node/footnote/definition.ts +56 -54
- package/src/node/footnote/reference.ts +47 -45
- package/src/node/table/command.ts +169 -93
- package/src/node/table/input.ts +32 -15
- package/src/node/table/schema.ts +12 -13
- package/src/node/table/utils.ts +120 -84
- package/src/node/task-list-item.ts +100 -88
- package/src/plugin/keep-table-align-plugin.ts +7 -14
- package/src/plugin/remark-gfm-plugin.ts +2 -1
- package/src/plugin/table-editing-plugin.ts +3 -1
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
import { paragraphSchema } from '@milkdown/preset-commonmark'
|
|
2
2
|
import { Selection } from '@milkdown/prose/state'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CellSelection,
|
|
5
|
+
addColumnAfter,
|
|
6
|
+
addColumnBefore,
|
|
7
|
+
deleteColumn,
|
|
8
|
+
deleteRow,
|
|
9
|
+
deleteTable,
|
|
10
|
+
goToNextCell,
|
|
11
|
+
isInTable,
|
|
12
|
+
selectedRect,
|
|
13
|
+
setCellAttr,
|
|
14
|
+
} from '@milkdown/prose/tables'
|
|
4
15
|
import { $command } from '@milkdown/utils'
|
|
5
16
|
import { findParentNodeType } from '@milkdown/prose'
|
|
6
17
|
import { withMeta } from '../../__internal__'
|
|
7
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
addRowWithAlignment,
|
|
20
|
+
createTable,
|
|
21
|
+
moveCol,
|
|
22
|
+
moveRow,
|
|
23
|
+
selectCol,
|
|
24
|
+
selectRow,
|
|
25
|
+
selectTable,
|
|
26
|
+
} from './utils'
|
|
8
27
|
import { tableSchema } from './schema'
|
|
9
28
|
|
|
10
29
|
/// A command for moving cursor to previous cell.
|
|
11
|
-
export const goToPrevTableCellCommand = $command(
|
|
30
|
+
export const goToPrevTableCellCommand = $command(
|
|
31
|
+
'GoToPrevTableCell',
|
|
32
|
+
() => () => goToNextCell(-1)
|
|
33
|
+
)
|
|
12
34
|
|
|
13
35
|
withMeta(goToPrevTableCellCommand, {
|
|
14
36
|
displayName: 'Command<goToPrevTableCellCommand>',
|
|
@@ -16,7 +38,10 @@ withMeta(goToPrevTableCellCommand, {
|
|
|
16
38
|
})
|
|
17
39
|
|
|
18
40
|
/// A command for moving cursor to next cell.
|
|
19
|
-
export const goToNextTableCellCommand = $command(
|
|
41
|
+
export const goToNextTableCellCommand = $command(
|
|
42
|
+
'GoToNextTableCell',
|
|
43
|
+
() => () => goToNextCell(1)
|
|
44
|
+
)
|
|
20
45
|
|
|
21
46
|
withMeta(goToNextTableCellCommand, {
|
|
22
47
|
displayName: 'Command<goToNextTableCellCommand>',
|
|
@@ -24,24 +49,28 @@ withMeta(goToNextTableCellCommand, {
|
|
|
24
49
|
})
|
|
25
50
|
|
|
26
51
|
/// A command for quitting current table and insert a new paragraph node.
|
|
27
|
-
export const exitTable = $command(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return false
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
export const exitTable = $command(
|
|
53
|
+
'ExitTable',
|
|
54
|
+
(ctx) => () => (state, dispatch) => {
|
|
55
|
+
if (!isInTable(state)) return false
|
|
56
|
+
|
|
57
|
+
const { $head } = state.selection
|
|
58
|
+
const table = findParentNodeType($head, tableSchema.type(ctx))
|
|
59
|
+
if (!table) return false
|
|
60
|
+
|
|
61
|
+
const { to } = table
|
|
62
|
+
|
|
63
|
+
const tr = state.tr.replaceWith(
|
|
64
|
+
to,
|
|
65
|
+
to,
|
|
66
|
+
paragraphSchema.type(ctx).createAndFill()!
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
tr.setSelection(Selection.near(tr.doc.resolve(to), 1)).scrollIntoView()
|
|
70
|
+
dispatch?.(tr)
|
|
71
|
+
return true
|
|
72
|
+
}
|
|
73
|
+
)
|
|
45
74
|
|
|
46
75
|
withMeta(exitTable, {
|
|
47
76
|
displayName: 'Command<breakTableCommand>',
|
|
@@ -51,19 +80,23 @@ withMeta(exitTable, {
|
|
|
51
80
|
/// A command for inserting a table.
|
|
52
81
|
/// You can specify the number of rows and columns.
|
|
53
82
|
/// By default, it will insert a 3x3 table.
|
|
54
|
-
export const insertTableCommand = $command(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
83
|
+
export const insertTableCommand = $command(
|
|
84
|
+
'InsertTable',
|
|
85
|
+
(ctx) =>
|
|
86
|
+
({ row, col }: { row?: number; col?: number } = {}) =>
|
|
87
|
+
(state, dispatch) => {
|
|
88
|
+
const { selection, tr } = state
|
|
89
|
+
const { from } = selection
|
|
90
|
+
const table = createTable(ctx, row, col)
|
|
91
|
+
const _tr = tr.replaceSelectionWith(table)
|
|
92
|
+
const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true)
|
|
93
|
+
if (sel) _tr.setSelection(sel)
|
|
94
|
+
|
|
95
|
+
dispatch?.(_tr)
|
|
96
|
+
|
|
97
|
+
return true
|
|
98
|
+
}
|
|
99
|
+
)
|
|
67
100
|
|
|
68
101
|
withMeta(insertTableCommand, {
|
|
69
102
|
displayName: 'Command<insertTableCommand>',
|
|
@@ -72,14 +105,19 @@ withMeta(insertTableCommand, {
|
|
|
72
105
|
|
|
73
106
|
/// A command for moving a row in a table.
|
|
74
107
|
/// You should specify the `from` and `to` index.
|
|
75
|
-
export const moveRowCommand = $command(
|
|
76
|
-
|
|
108
|
+
export const moveRowCommand = $command(
|
|
109
|
+
'MoveRow',
|
|
110
|
+
() =>
|
|
111
|
+
({ from, to, pos }: { from?: number; to?: number; pos?: number } = {}) =>
|
|
77
112
|
(state, dispatch) => {
|
|
78
113
|
const { tr } = state
|
|
79
|
-
const result = dispatch?.(
|
|
114
|
+
const result = dispatch?.(
|
|
115
|
+
moveRow({ tr, origin: from ?? 0, target: to ?? 0, pos, select: true })
|
|
116
|
+
)
|
|
80
117
|
|
|
81
118
|
return Boolean(result)
|
|
82
|
-
}
|
|
119
|
+
}
|
|
120
|
+
)
|
|
83
121
|
|
|
84
122
|
withMeta(moveRowCommand, {
|
|
85
123
|
displayName: 'Command<moveRowCommand>',
|
|
@@ -88,14 +126,19 @@ withMeta(moveRowCommand, {
|
|
|
88
126
|
|
|
89
127
|
/// A command for moving a column in a table.
|
|
90
128
|
/// You should specify the `from` and `to` index.
|
|
91
|
-
export const moveColCommand = $command(
|
|
92
|
-
|
|
129
|
+
export const moveColCommand = $command(
|
|
130
|
+
'MoveCol',
|
|
131
|
+
() =>
|
|
132
|
+
({ from, to, pos }: { from?: number; to?: number; pos?: number } = {}) =>
|
|
93
133
|
(state, dispatch) => {
|
|
94
134
|
const { tr } = state
|
|
95
|
-
const result = dispatch?.(
|
|
135
|
+
const result = dispatch?.(
|
|
136
|
+
moveCol({ tr, origin: from ?? 0, target: to ?? 0, pos, select: true })
|
|
137
|
+
)
|
|
96
138
|
|
|
97
139
|
return Boolean(result)
|
|
98
|
-
}
|
|
140
|
+
}
|
|
141
|
+
)
|
|
99
142
|
|
|
100
143
|
withMeta(moveColCommand, {
|
|
101
144
|
displayName: 'Command<moveColCommand>',
|
|
@@ -103,13 +146,20 @@ withMeta(moveColCommand, {
|
|
|
103
146
|
})
|
|
104
147
|
|
|
105
148
|
/// A command for selecting a row.
|
|
106
|
-
export const selectRowCommand = $command<
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
149
|
+
export const selectRowCommand = $command<
|
|
150
|
+
{ index: number; pos?: number },
|
|
151
|
+
'SelectRow'
|
|
152
|
+
>(
|
|
153
|
+
'SelectRow',
|
|
154
|
+
() =>
|
|
155
|
+
(payload: { index: number; pos?: number } = { index: 0 }) =>
|
|
156
|
+
(state, dispatch) => {
|
|
157
|
+
const { tr } = state
|
|
158
|
+
const result = dispatch?.(selectRow(payload.index, payload.pos)(tr))
|
|
110
159
|
|
|
111
|
-
|
|
112
|
-
|
|
160
|
+
return Boolean(result)
|
|
161
|
+
}
|
|
162
|
+
)
|
|
113
163
|
|
|
114
164
|
withMeta(selectRowCommand, {
|
|
115
165
|
displayName: 'Command<selectRowCommand>',
|
|
@@ -117,13 +167,20 @@ withMeta(selectRowCommand, {
|
|
|
117
167
|
})
|
|
118
168
|
|
|
119
169
|
/// A command for selecting a column.
|
|
120
|
-
export const selectColCommand = $command<
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
170
|
+
export const selectColCommand = $command<
|
|
171
|
+
{ index: number; pos?: number },
|
|
172
|
+
'SelectCol'
|
|
173
|
+
>(
|
|
174
|
+
'SelectCol',
|
|
175
|
+
() =>
|
|
176
|
+
(payload: { index: number; pos?: number } = { index: 0 }) =>
|
|
177
|
+
(state, dispatch) => {
|
|
178
|
+
const { tr } = state
|
|
179
|
+
const result = dispatch?.(selectCol(payload.index, payload.pos)(tr))
|
|
124
180
|
|
|
125
|
-
|
|
126
|
-
|
|
181
|
+
return Boolean(result)
|
|
182
|
+
}
|
|
183
|
+
)
|
|
127
184
|
|
|
128
185
|
withMeta(selectColCommand, {
|
|
129
186
|
displayName: 'Command<selectColCommand>',
|
|
@@ -131,12 +188,15 @@ withMeta(selectColCommand, {
|
|
|
131
188
|
})
|
|
132
189
|
|
|
133
190
|
/// A command for selecting a table.
|
|
134
|
-
export const selectTableCommand = $command(
|
|
135
|
-
|
|
136
|
-
|
|
191
|
+
export const selectTableCommand = $command(
|
|
192
|
+
'SelectTable',
|
|
193
|
+
() => () => (state, dispatch) => {
|
|
194
|
+
const { tr } = state
|
|
195
|
+
const result = dispatch?.(selectTable(tr))
|
|
137
196
|
|
|
138
|
-
|
|
139
|
-
}
|
|
197
|
+
return Boolean(result)
|
|
198
|
+
}
|
|
199
|
+
)
|
|
140
200
|
|
|
141
201
|
withMeta(selectTableCommand, {
|
|
142
202
|
displayName: 'Command<selectTableCommand>',
|
|
@@ -146,23 +206,21 @@ withMeta(selectTableCommand, {
|
|
|
146
206
|
/// A command for deleting selected cells.
|
|
147
207
|
/// If the selection is a row or column, the row or column will be deleted.
|
|
148
208
|
/// If all cells are selected, the table will be deleted.
|
|
149
|
-
export const deleteSelectedCellsCommand = $command(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
209
|
+
export const deleteSelectedCellsCommand = $command(
|
|
210
|
+
'DeleteSelectedCells',
|
|
211
|
+
() => () => (state, dispatch) => {
|
|
212
|
+
const { selection } = state
|
|
213
|
+
if (!(selection instanceof CellSelection)) return false
|
|
153
214
|
|
|
154
|
-
|
|
155
|
-
|
|
215
|
+
const isRow = selection.isRowSelection()
|
|
216
|
+
const isCol = selection.isColSelection()
|
|
156
217
|
|
|
157
|
-
|
|
158
|
-
return deleteTable(state, dispatch)
|
|
218
|
+
if (isRow && isCol) return deleteTable(state, dispatch)
|
|
159
219
|
|
|
160
|
-
|
|
161
|
-
return
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return deleteRow(state, dispatch)
|
|
165
|
-
})
|
|
220
|
+
if (isCol) return deleteColumn(state, dispatch)
|
|
221
|
+
else return deleteRow(state, dispatch)
|
|
222
|
+
}
|
|
223
|
+
)
|
|
166
224
|
|
|
167
225
|
withMeta(deleteSelectedCellsCommand, {
|
|
168
226
|
displayName: 'Command<deleteSelectedCellsCommand>',
|
|
@@ -170,7 +228,10 @@ withMeta(deleteSelectedCellsCommand, {
|
|
|
170
228
|
})
|
|
171
229
|
|
|
172
230
|
/// A command for adding a column before the current column.
|
|
173
|
-
export const addColBeforeCommand = $command(
|
|
231
|
+
export const addColBeforeCommand = $command(
|
|
232
|
+
'AddColBefore',
|
|
233
|
+
() => () => addColumnBefore
|
|
234
|
+
)
|
|
174
235
|
|
|
175
236
|
withMeta(addColBeforeCommand, {
|
|
176
237
|
displayName: 'Command<addColBeforeCommand>',
|
|
@@ -178,7 +239,10 @@ withMeta(addColBeforeCommand, {
|
|
|
178
239
|
})
|
|
179
240
|
|
|
180
241
|
/// A command for adding a column after the current column.
|
|
181
|
-
export const addColAfterCommand = $command(
|
|
242
|
+
export const addColAfterCommand = $command(
|
|
243
|
+
'AddColAfter',
|
|
244
|
+
() => () => addColumnAfter
|
|
245
|
+
)
|
|
182
246
|
|
|
183
247
|
withMeta(addColAfterCommand, {
|
|
184
248
|
displayName: 'Command<addColAfterCommand>',
|
|
@@ -186,15 +250,17 @@ withMeta(addColAfterCommand, {
|
|
|
186
250
|
})
|
|
187
251
|
|
|
188
252
|
/// A command for adding a row before the current row.
|
|
189
|
-
export const addRowBeforeCommand = $command(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
253
|
+
export const addRowBeforeCommand = $command(
|
|
254
|
+
'AddRowBefore',
|
|
255
|
+
(ctx) => () => (state, dispatch) => {
|
|
256
|
+
if (!isInTable(state)) return false
|
|
257
|
+
if (dispatch) {
|
|
258
|
+
const rect = selectedRect(state)
|
|
259
|
+
dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.top))
|
|
260
|
+
}
|
|
261
|
+
return true
|
|
195
262
|
}
|
|
196
|
-
|
|
197
|
-
})
|
|
263
|
+
)
|
|
198
264
|
|
|
199
265
|
withMeta(addRowBeforeCommand, {
|
|
200
266
|
displayName: 'Command<addRowBeforeCommand>',
|
|
@@ -202,15 +268,17 @@ withMeta(addRowBeforeCommand, {
|
|
|
202
268
|
})
|
|
203
269
|
|
|
204
270
|
/// A command for adding a row after the current row.
|
|
205
|
-
export const addRowAfterCommand = $command(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
271
|
+
export const addRowAfterCommand = $command(
|
|
272
|
+
'AddRowAfter',
|
|
273
|
+
(ctx) => () => (state, dispatch) => {
|
|
274
|
+
if (!isInTable(state)) return false
|
|
275
|
+
if (dispatch) {
|
|
276
|
+
const rect = selectedRect(state)
|
|
277
|
+
dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.bottom))
|
|
278
|
+
}
|
|
279
|
+
return true
|
|
211
280
|
}
|
|
212
|
-
|
|
213
|
-
})
|
|
281
|
+
)
|
|
214
282
|
|
|
215
283
|
withMeta(addRowAfterCommand, {
|
|
216
284
|
displayName: 'Command<addRowAfterCommand>',
|
|
@@ -220,7 +288,15 @@ withMeta(addRowAfterCommand, {
|
|
|
220
288
|
/// A command for setting alignment property for selected cells.
|
|
221
289
|
/// You can specify the alignment as `left`, `center`, or `right`.
|
|
222
290
|
/// It's `left` by default.
|
|
223
|
-
export const setAlignCommand = $command<
|
|
291
|
+
export const setAlignCommand = $command<
|
|
292
|
+
'left' | 'center' | 'right',
|
|
293
|
+
'SetAlign'
|
|
294
|
+
>(
|
|
295
|
+
'SetAlign',
|
|
296
|
+
() =>
|
|
297
|
+
(alignment = 'left') =>
|
|
298
|
+
setCellAttr('alignment', alignment)
|
|
299
|
+
)
|
|
224
300
|
|
|
225
301
|
withMeta(setAlignCommand, {
|
|
226
302
|
displayName: 'Command<setAlignCommand>',
|
package/src/node/table/input.ts
CHANGED
|
@@ -5,26 +5,43 @@ import { $inputRule, $useKeymap } from '@milkdown/utils'
|
|
|
5
5
|
import { withMeta } from '../../__internal__'
|
|
6
6
|
import { createTable } from './utils'
|
|
7
7
|
import { tableSchema } from './schema'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
exitTable,
|
|
10
|
+
goToNextTableCellCommand,
|
|
11
|
+
goToPrevTableCellCommand,
|
|
12
|
+
} from './command'
|
|
9
13
|
|
|
10
14
|
/// A input rule for creating table.
|
|
11
15
|
/// For example, `|2x2|` will create a 2x2 table.
|
|
12
|
-
export const insertTableInputRule = $inputRule(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
export const insertTableInputRule = $inputRule(
|
|
17
|
+
(ctx) =>
|
|
18
|
+
new InputRule(
|
|
19
|
+
/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,
|
|
20
|
+
(state, match, start, end) => {
|
|
21
|
+
const $start = state.doc.resolve(start)
|
|
22
|
+
if (
|
|
23
|
+
!$start
|
|
24
|
+
.node(-1)
|
|
25
|
+
.canReplaceWith(
|
|
26
|
+
$start.index(-1),
|
|
27
|
+
$start.indexAfter(-1),
|
|
28
|
+
tableSchema.type(ctx)
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
return null
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
const tableNode = createTable(
|
|
34
|
+
ctx,
|
|
35
|
+
Number(match.groups?.row),
|
|
36
|
+
Number(match.groups?.col)
|
|
37
|
+
)
|
|
38
|
+
const tr = state.tr.replaceRangeWith(start, end, tableNode)
|
|
39
|
+
return tr
|
|
40
|
+
.setSelection(TextSelection.create(tr.doc, start + 3))
|
|
41
|
+
.scrollIntoView()
|
|
42
|
+
}
|
|
23
43
|
)
|
|
24
|
-
|
|
25
|
-
return tr.setSelection(TextSelection.create(tr.doc, start + 3)).scrollIntoView()
|
|
26
|
-
},
|
|
27
|
-
))
|
|
44
|
+
)
|
|
28
45
|
|
|
29
46
|
withMeta(insertTableInputRule, {
|
|
30
47
|
displayName: 'InputRule<insertTableInputRule>',
|
package/src/node/table/schema.ts
CHANGED
|
@@ -10,7 +10,7 @@ const originalSchema = tableNodes({
|
|
|
10
10
|
cellAttributes: {
|
|
11
11
|
alignment: {
|
|
12
12
|
default: 'left',
|
|
13
|
-
getFromDOM: dom =>
|
|
13
|
+
getFromDOM: (dom) => dom.style.textAlign || 'left',
|
|
14
14
|
setDOMAttr: (value, attrs) => {
|
|
15
15
|
attrs.style = `text-align: ${value || 'left'}`
|
|
16
16
|
},
|
|
@@ -24,7 +24,7 @@ export const tableSchema = $nodeSchema('table', () => ({
|
|
|
24
24
|
content: 'table_header_row table_row+',
|
|
25
25
|
disableDropCursor: true,
|
|
26
26
|
parseMarkdown: {
|
|
27
|
-
match: node => node.type === 'table',
|
|
27
|
+
match: (node) => node.type === 'table',
|
|
28
28
|
runner: (state, node, type) => {
|
|
29
29
|
const align = node.align as (string | null)[]
|
|
30
30
|
const children = (node.children as MarkdownNode[]).map((x, i) => ({
|
|
@@ -38,11 +38,10 @@ export const tableSchema = $nodeSchema('table', () => ({
|
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
toMarkdown: {
|
|
41
|
-
match: node => node.type.name === 'table',
|
|
41
|
+
match: (node) => node.type.name === 'table',
|
|
42
42
|
runner: (state, node) => {
|
|
43
43
|
const firstLine = node.content.firstChild?.content
|
|
44
|
-
if (!firstLine)
|
|
45
|
-
return
|
|
44
|
+
if (!firstLine) return
|
|
46
45
|
|
|
47
46
|
const align: (string | null)[] = []
|
|
48
47
|
firstLine.forEach((cell) => {
|
|
@@ -75,7 +74,7 @@ export const tableHeaderRowSchema = $nodeSchema('table_header_row', () => ({
|
|
|
75
74
|
return ['tr', { 'data-is-header': true }, 0]
|
|
76
75
|
},
|
|
77
76
|
parseMarkdown: {
|
|
78
|
-
match: node => Boolean(node.type === 'tableRow' && node.isHeader),
|
|
77
|
+
match: (node) => Boolean(node.type === 'tableRow' && node.isHeader),
|
|
79
78
|
runner: (state, node, type) => {
|
|
80
79
|
const align = node.align as (string | null)[]
|
|
81
80
|
const children = (node.children as MarkdownNode[]).map((x, i) => ({
|
|
@@ -89,7 +88,7 @@ export const tableHeaderRowSchema = $nodeSchema('table_header_row', () => ({
|
|
|
89
88
|
},
|
|
90
89
|
},
|
|
91
90
|
toMarkdown: {
|
|
92
|
-
match: node => node.type.name === 'table_header_row',
|
|
91
|
+
match: (node) => node.type.name === 'table_header_row',
|
|
93
92
|
runner: (state, node) => {
|
|
94
93
|
state.openNode('tableRow', undefined, { isHeader: true })
|
|
95
94
|
state.next(node.content)
|
|
@@ -114,7 +113,7 @@ export const tableRowSchema = $nodeSchema('table_row', () => ({
|
|
|
114
113
|
disableDropCursor: true,
|
|
115
114
|
content: '(table_cell)*',
|
|
116
115
|
parseMarkdown: {
|
|
117
|
-
match: node => node.type === 'tableRow',
|
|
116
|
+
match: (node) => node.type === 'tableRow',
|
|
118
117
|
runner: (state, node, type) => {
|
|
119
118
|
const align = node.align as (string | null)[]
|
|
120
119
|
const children = (node.children as MarkdownNode[]).map((x, i) => ({
|
|
@@ -127,7 +126,7 @@ export const tableRowSchema = $nodeSchema('table_row', () => ({
|
|
|
127
126
|
},
|
|
128
127
|
},
|
|
129
128
|
toMarkdown: {
|
|
130
|
-
match: node => node.type.name === 'table_row',
|
|
129
|
+
match: (node) => node.type.name === 'table_row',
|
|
131
130
|
runner: (state, node) => {
|
|
132
131
|
state.openNode('tableRow')
|
|
133
132
|
state.next(node.content)
|
|
@@ -151,7 +150,7 @@ export const tableCellSchema = $nodeSchema('table_cell', () => ({
|
|
|
151
150
|
...originalSchema.table_cell,
|
|
152
151
|
disableDropCursor: true,
|
|
153
152
|
parseMarkdown: {
|
|
154
|
-
match: node => node.type === 'tableCell' && !node.isHeader,
|
|
153
|
+
match: (node) => node.type === 'tableCell' && !node.isHeader,
|
|
155
154
|
runner: (state, node, type) => {
|
|
156
155
|
const align = node.align as string
|
|
157
156
|
state
|
|
@@ -163,7 +162,7 @@ export const tableCellSchema = $nodeSchema('table_cell', () => ({
|
|
|
163
162
|
},
|
|
164
163
|
},
|
|
165
164
|
toMarkdown: {
|
|
166
|
-
match: node => node.type.name === 'table_cell',
|
|
165
|
+
match: (node) => node.type.name === 'table_cell',
|
|
167
166
|
runner: (state, node) => {
|
|
168
167
|
state.openNode('tableCell').next(node.content).closeNode()
|
|
169
168
|
},
|
|
@@ -185,7 +184,7 @@ export const tableHeaderSchema = $nodeSchema('table_header', () => ({
|
|
|
185
184
|
...originalSchema.table_header,
|
|
186
185
|
disableDropCursor: true,
|
|
187
186
|
parseMarkdown: {
|
|
188
|
-
match: node => node.type === 'tableCell' && !!node.isHeader,
|
|
187
|
+
match: (node) => node.type === 'tableCell' && !!node.isHeader,
|
|
189
188
|
runner: (state, node, type) => {
|
|
190
189
|
const align = node.align as string
|
|
191
190
|
state.openNode(type, { alignment: align })
|
|
@@ -196,7 +195,7 @@ export const tableHeaderSchema = $nodeSchema('table_header', () => ({
|
|
|
196
195
|
},
|
|
197
196
|
},
|
|
198
197
|
toMarkdown: {
|
|
199
|
-
match: node => node.type.name === 'table_header',
|
|
198
|
+
match: (node) => node.type.name === 'table_header',
|
|
200
199
|
runner: (state, node) => {
|
|
201
200
|
state.openNode('tableCell')
|
|
202
201
|
state.next(node.content)
|