Renders an inline node as plain text. Asserts that the node is an inline and has no non-inline children.
pub fn renderInlineNodeText(
doc: Document,
node: Node.Index,
writer: *Writer,
) Writer.Error!void
pub fn renderInlineNodeText(
doc: Document,
node: Node.Index,
writer: *Writer,
) Writer.Error!void {
const data = doc.nodes.items(.data)[@backingInt(node)];
switch (doc.nodes.items(.tag)[@backingInt(node)]) {
.root,
.list,
.list_item,
.table,
.table_row,
.table_cell,
.heading,
.code_block,
.blockquote,
.paragraph,
.thematic_break,
=> unreachable, // Blocks
.link, .image => {
for (doc.extraChildren(data.link.children)) |child| {
try renderInlineNodeText(doc, child, writer);
}
},
.strong => {
for (doc.extraChildren(data.container.children)) |child| {
try renderInlineNodeText(doc, child, writer);
}
},
.emphasis => {
for (doc.extraChildren(data.container.children)) |child| {
try renderInlineNodeText(doc, child, writer);
}
},
.autolink, .code_span, .text => {
const content = doc.string(data.text.content);
try writer.print("{f}", .{fmtHtml(content)});
},
.line_break => {
try writer.writeAll("\n");
},
}
}