Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

renderInlineNodeText

Renders an inline node as plain text. Asserts that the node is an inline and has no non-inline children.

renderer.renderInlineNodeText
pub fn renderInlineNodeText(
    doc: Document,
    node: Node.Index,
    writer: *Writer,
) Writer.Error!void

File

lib/docs/wasm/markdown/renderer.zig:189

Code

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");
        },
    }
}