Allow fragments to be used in DeadDocument.

They work like React.Fragment except we don't have components yet
so it has to be a special node.
This commit is contained in:
gnuxie
2023-02-10 17:10:17 +00:00
committed by Gnuxie
parent cbddf71ebe
commit b59247df61
4 changed files with 13 additions and 1 deletions
@@ -63,6 +63,7 @@ export enum NodeTag {
BoldFace = 'b',
ItalicFace = 'i',
Anchor = 'a',
Fragment = 'fragment',
}
/**
@@ -62,4 +62,7 @@ HTML_RENDERER.registerRenderer<FringeLeafRenderFunction<TransactionalOutputConte
context.output.writeString('>')
},
staticString('</a>')
).registerInnerNode(NodeTag.Fragment,
blank,
blank
);
@@ -132,4 +132,7 @@ MARKDOWN_RENDERER.registerRenderer<FringeLeafRenderFunction<TransactionalOutputC
}
context.output.writeString(`](${href})`);
}
).registerInnerNode(NodeTag.Fragment,
blank,
blank
);
+6 -1
View File
@@ -23,8 +23,13 @@ export function JSXFactory(tag: NodeTag, properties: any, ...rawChildren: (Docum
makeLeafNode<TextNode>(NodeTag.TextNode, node, (rawChild as number).toString());
} else if (Array.isArray(rawChild)) {
rawChild.forEach(ensureChild);
// Then it's a DocumentNode|LeafNode
} else if (typeof rawChild.leafNode === 'boolean') {
node.addChild(rawChild);
if (rawChild.tag === NodeTag.Fragment) {
(rawChild as DocumentNode).getChildren().forEach(node.addChild, node);
} else {
node.addChild(rawChild);
}
} else {
const presentationType = presentationTypeOf(rawChild);
if (presentationType !== undefined) {