fix: remove empty mark attributes from getDebugJSON

This commit is contained in:
Philipp Kühn
2021-12-17 00:09:09 +01:00
parent 209b3547e6
commit 07cabe65f4

View File

@@ -9,12 +9,19 @@ interface DebugJSONContent extends JSONContent {
export function getDebugJSON(node: ProseMirrorNode, startOffset = 0): DebugJSONContent { export function getDebugJSON(node: ProseMirrorNode, startOffset = 0): DebugJSONContent {
const isTopNode = node.type === node.type.schema.topNodeType const isTopNode = node.type === node.type.schema.topNodeType
const increment = isTopNode ? 0 : 1 const increment = isTopNode ? 0 : 1
const from = startOffset // + offset const from = startOffset
const to = from + node.nodeSize const to = from + node.nodeSize
const marks = node.marks.map(mark => ({ const marks = node.marks.map(mark => {
const output: { type: string, attrs?: Record<string, any> } = {
type: mark.type.name, type: mark.type.name,
attrs: { ...mark.attrs }, }
}))
if (Object.keys(mark.attrs).length) {
output.attrs = { ...mark.attrs }
}
return output
})
const attrs = { ...node.attrs } const attrs = { ...node.attrs }
const output: DebugJSONContent = { const output: DebugJSONContent = {
type: node.type.name, type: node.type.name,