Add font tag to DeadDocument

https://github.com/Gnuxie/Draupnir/pull/85
This commit is contained in:
gnuxie
2023-09-01 19:21:58 +01:00
committed by Gnuxie
parent ea49b0a536
commit 1e82c15d82
3 changed files with 26 additions and 10 deletions
@@ -66,6 +66,7 @@ export enum NodeTag {
Fragment = 'fragment',
Details = 'details',
Summary = 'summary',
Font = 'font',
}
/**
@@ -4,9 +4,26 @@
*/
import { htmlEscape } from "../../utils";
import { FringeLeafRenderFunction, FringeType, LeafNode, NodeTag, SimpleFringeRenderer } from "./DeadDocument";
import { DocumentNode, FringeLeafRenderFunction, FringeType, LeafNode, NodeTag, SimpleFringeRenderer, TagDynamicEnvironment } from "./DeadDocument";
import { blank, staticString, TransactionalOutputContext } from "./DeadDocumentMarkdown";
function writeAttributableNode(tagName: string, _fringe: FringeType, node: DocumentNode, context: TransactionalOutputContext, _environment: TagDynamicEnvironment) {
context.output.writeString(`<${tagName}`);
if (node.attributeMap.size > 0) {
for (const [key, value] of node.attributeMap.entries()) {
context.output.writeString(` ${htmlEscape(key)}="${htmlEscape(value)}"`);
}
}
context.output.writeString('>')
}
function attributableNode(tagName: string) {
return function(fringe: FringeType, node: DocumentNode, context: TransactionalOutputContext, environment: TagDynamicEnvironment) {
writeAttributableNode(tagName, fringe, node, context, environment);
}
}
export const HTML_RENDERER = new SimpleFringeRenderer<TransactionalOutputContext>();
HTML_RENDERER.registerRenderer<FringeLeafRenderFunction<TransactionalOutputContext>>(
@@ -52,16 +69,11 @@ HTML_RENDERER.registerRenderer<FringeLeafRenderFunction<TransactionalOutputConte
staticString('<i>'),
staticString('</i>')
).registerInnerNode(NodeTag.Anchor,
function(_fringe, node, context, _environment) {
context.output.writeString('<a');
if (node.attributeMap.size > 0) {
for (const [key, value] of node.attributeMap.entries()) {
context.output.writeString(` ${htmlEscape(key)}="${htmlEscape(value)}"`);
}
}
context.output.writeString('>')
},
attributableNode('a'),
staticString('</a>')
).registerInnerNode(NodeTag.Font,
attributableNode('font'),
staticString('</font>')
).registerInnerNode(NodeTag.Root,
blank,
blank
@@ -142,4 +142,7 @@ MARKDOWN_RENDERER.registerRenderer<FringeLeafRenderFunction<TransactionalOutputC
).registerInnerNode(NodeTag.Summary,
staticString('<summary>'),
staticString('</summary>')
).registerInnerNode(NodeTag.Font,
blank,
blank
);