ElyMark: a table stays a table whatever its spacing; edits keep the document's table style (R2.13)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 03:50:52 -04:00
1 parent 7049a6a4aa
commit f28768634f
5 files changed
+31 -7

No files matched your search

+6 -3
View File
@@ -1,5 +1,5 @@
// Blocks Milkdown cannot write back stay raw text (§14.3).
import { editorViewCtx, remarkCtx, schemaCtx, serializerCtx } from '@milkdown/kit/core'
import { editorViewCtx, parserCtx, remarkCtx, schemaCtx, serializerCtx } from '@milkdown/kit/core'
import { Fragment } from '@milkdown/kit/prose/model'
import { Selection } from '@milkdown/kit/prose/state'
import { $nodeSchema } from '@milkdown/kit/utils'
@@ -51,6 +51,10 @@ export function faithful(ctx, original) {
const schema = ctx.get(schemaCtx)
const serializer = ctx.get(serializerCtx)
const written = (nodes) => serializer(schema.topNodeType.create(null, nodes)).replace(/\n+$/, '')
const parser = ctx.get(parserCtx)
// A table's spacing is free; its cells must match.
const kept = (node, text) =>
written([node]) === text || (node.type.name === 'table' && parser(text).firstChild?.eq(node))
const rawOf = ([from, to]) => {
const text = original.slice(from, to)
return schema.nodes.ely_raw.create(null, text ? schema.text(text) : null)
@@ -68,8 +72,7 @@ export function faithful(ctx, original) {
if (!blank)
parsed.forEach((node, _, index) => {
gap(last, at[index][0])
const exact = written([node]) === original.slice(...at[index])
nodes.push(exact ? node : rawOf(at[index]))
nodes.push(kept(node, original.slice(...at[index])) ? node : rawOf(at[index]))
places.push(at[index])
last = at[index][1]
})