tiny.zen.renderCode
Defined in code.
Source
Source: lib/zen/src/code.zig:31
zig
pub fn render( allocator: Allocator, out: *std.ArrayList(u8), info_text: []const u8, source: []const u8, options: Options,) !void { const info = parseInfo(info_text); const anchors = optionValue(info_text, "anchors") orelse ""; const exact_source = hasOption(info_text, "source", "exact"); const wide = exact_source or hasOption(info_text, "role", "wide"); try out.appendSlice(allocator, "<div class=\"zen-code-block"); if (options.word_wrap) { try out.appendSlice(allocator, " zen-code-wrap"); } else { try out.appendSlice(allocator, " zen-code-nowrap"); } if (!options.line_numbers) try out.appendSlice(allocator, " zen-code-no-lines"); if (exact_source) { try out.appendSlice(allocator, " zen-source-listing zen-role-wide"); } else if (wide) { try out.appendSlice(allocator, " zen-code-longform zen-role-wide"); } else { try out.appendSlice(allocator, " zen-code-example zen-role-reading"); } try out.append(allocator, '"'); if (info.language.len != 0) { try out.appendSlice(allocator, " data-language=\""); try html.appendAttributeEscaped(out, allocator, info.language); try out.append(allocator, '"'); } if (exact_source) { try out.appendSlice(allocator, " data-source=\"exact\""); } try out.append(allocator, '>'); if ((options.titles and info.title.len != 0) or (options.language_labels and info.language.len != 0)) { try out.appendSlice(allocator, "<div class=\"zen-code-header\">"); if (options.titles and info.title.len != 0) { try out.appendSlice(allocator, "<span class=\"zen-code-title\">"); try html.appendEscaped(out, allocator, info.title); try out.appendSlice(allocator, "</span>"); } if (options.language_labels and info.language.len != 0) { try out.appendSlice(allocator, "<span class=\"zen-code-language\">"); try html.appendEscaped(out, allocator, info.language); try out.appendSlice(allocator, "</span>"); } try out.appendSlice(allocator, "</div>"); } try out.appendSlice(allocator, "<pre class=\"zen-code\"><code"); if (info.language.len != 0) { try out.appendSlice(allocator, " class=\"language-"); try html.appendAttributeEscaped(out, allocator, info.language); try out.append(allocator, '"'); } try out.append(allocator, '>'); try appendLines(allocator, out, info.language, source, anchors, options); try out.appendSlice(allocator, "</code></pre></div>\n");}Source: lib/zen/src/root.zig:175
zig
/// Appends escaped, optionally highlighted code-block HTML to caller-owned output.pub const renderCode = code.render;Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |