Skip to documentation
SLOP

tiny.zen.html

Reference tiny.zen html

Defined in tiny.zen.

API (9)

Actions

Public operations.

No direct callersNo direct callstiny.zenhtml
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsprivate sourcelib.zen.src.code.AnchorCursorappendForLinecoderenderprivate sourcelib.zen.src.markdownappendContentsItemprivate sourcelib.zen.src.markdownappendFootnoteReferenceprivate sourcelib.zen.src.markdownappendFootnotes+2 morehtmlappendEscapedhtmlappendAttributeEscaped
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallscoderenderhtmlappendAttributeEscapedhtmlescapedAllocprivate sourcelib.zen.src.markdownappendContentsprivate sourcelib.zen.src.markdownappendInlineIndexed+7 morehtmlappendEscapedBytehtmlappendEscaped
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callshtmlappendEscapedprivate sourcelib.zen.src.markdownappendInlineIndexedprivate sourcelib.zen.src.markdownappendMarkdownEscapedprivate sourcelib.zen.src.syntax.HighlighterappendCprivate sourcelib.zen.src.syntax.HighlighterappendZightmlappendEscapedByte
Static calls · unresolved targets: 1 · external targets: 1.
Called byCallstest sourcelib.zen.src.htmltest: html escaping covers text and a...htmlappendEscapedhtmlescapedAlloc
Static calls · unresolved targets: 0 · external targets: 2.
Called byCallsprivate sourcelib.zen.src.diagram.ego.svgwriteEscapedtest sourcelib.zen.src.htmltest: html escaping covers text and a...htmlwriteEscapedThemeRenderPlaninspectprivate sourcelib.zen.src.htmlescapedByteLengthhtmlescapedLength
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.zen.src.htmltest: slug normalizes ascii heading t...htmlslugLengthhtmlwriteSlughtmlslug
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallshtmlslugtest sourcelib.zen.src.htmltest: slug length and caller storage ...htmlwriteSlugprivate sourcelib.zen.src.markdown.ResolvedHeadingIdlengthprivate sourcelib.zen.src.markdown.ResolvedHeadingIdwriteprivate sourcelib.zen.src.htmlisAsciiAlnumhtmlslugLength
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsprivate sourcelib.zen.src.diagram.ego.svgwriteEscapedtest sourcelib.zen.src.htmltest: html escaping covers text and a...tiny.zenrenderPageprivate sourcelib.zen.src.htmlcopyhtmlescapedLengthhtmlwriteEscaped
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallshtmlslugtest sourcelib.zen.src.htmltest: slug length and caller storage ...private sourcelib.zen.src.markdown.ResolvedHeadingIdwriteprivate sourcelib.zen.src.htmlisAsciiAlnumhtmlslugLengthhtmlwriteSlug
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/zen/src/html.zig

zig
const std = @import("std");const Allocator = std.mem.Allocator;pub fn appendEscaped(out: *std.ArrayList(u8), allocator: Allocator, value: []const u8) Allocator.Error!void {    for (value) |byte| try appendEscapedByte(out, allocator, byte);}pub fn appendAttributeEscaped(out: *std.ArrayList(u8), allocator: Allocator, value: []const u8) Allocator.Error!void {    try appendEscaped(out, allocator, value);}pub fn appendEscapedByte(out: *std.ArrayList(u8), allocator: Allocator, byte: u8) Allocator.Error!void {    switch (byte) {        '&' => try out.appendSlice(allocator, "&amp;"),        '<' => try out.appendSlice(allocator, "&lt;"),        '>' => try out.appendSlice(allocator, "&gt;"),        '"' => try out.appendSlice(allocator, "&quot;"),        '\'' => try out.appendSlice(allocator, "&#39;"),        else => try out.append(allocator, byte),    }}pub fn escapedLength(value: []const u8) error{CapacityOverflow}!usize {    var length: usize = 0;    for (value) |byte| {        length = std.math.add(usize, length, escapedByteLength(byte)) catch            return error.CapacityOverflow;    }    return length;}pub fn writeEscaped(out: []u8, value: []const u8) []u8 {    const length = escapedLength(value) catch unreachable;    std.debug.assert(out.len >= length);    var index: usize = 0;    for (value) |byte| switch (byte) {        '&' => copy(out, &index, "&amp;"),        '<' => copy(out, &index, "&lt;"),        '>' => copy(out, &index, "&gt;"),        '"' => copy(out, &index, "&quot;"),        '\'' => copy(out, &index, "&#39;"),        else => {            out[index] = byte;            index += 1;        },    };    std.debug.assert(index == length);    return out[0..index];}pub fn escapedAlloc(allocator: Allocator, value: []const u8) Allocator.Error![]u8 {    var out: std.ArrayList(u8) = .empty;    errdefer out.deinit(allocator);    try appendEscaped(&out, allocator, value);    return try out.toOwnedSlice(allocator);}pub fn slug(allocator: Allocator, value: []const u8) Allocator.Error![]u8 {    const out = try allocator.alloc(u8, slugLength(value));    _ = writeSlug(out, value);    return out;}pub fn slugLength(value: []const u8) usize {    var length: usize = 0;    var previous_dash = false;    for (value) |byte| {        if (isAsciiAlnum(byte)) {            length += 1;            previous_dash = false;        } else if (byte == ' ' or byte == '\t' or byte == '-' or byte == '_') {            if (!previous_dash and length != 0) {                length += 1;                previous_dash = true;            }        }    }    if (length != 0 and previous_dash) length -= 1;    return if (length == 0) "section".len else length;}pub fn writeSlug(out: []u8, value: []const u8) []u8 {    std.debug.assert(out.len >= slugLength(value));    var index: usize = 0;    var pending_dash = false;    for (value) |byte| {        if (isAsciiAlnum(byte)) {            if (pending_dash) {                out[index] = '-';                index += 1;            }            out[index] = std.ascii.toLower(byte);            index += 1;            pending_dash = false;        } else if (byte == ' ' or byte == '\t' or byte == '-' or byte == '_') {            if (index != 0) pending_dash = true;        }    }    if (index == 0) {        @memcpy(out[0.."section".len], "section");        index = "section".len;    }    std.debug.assert(index == slugLength(value));    return out[0..index];}fn isAsciiAlnum(byte: u8) bool {    return (byte >= 'a' and byte <= 'z') or        (byte >= 'A' and byte <= 'Z') or        (byte >= '0' and byte <= '9');}fn escapedByteLength(byte: u8) usize {    return switch (byte) {        '&' => "&amp;".len,        '<' => "&lt;".len,        '>' => "&gt;".len,        '"' => "&quot;".len,        '\'' => "&#39;".len,        else => 1,    };}fn copy(out: []u8, index: *usize, value: []const u8) void {    @memcpy(out[index.*..][0..value.len], value);    index.* += value.len;}test "html escaping covers text and attributes" {    const escaped = try escapedAlloc(std.testing.allocator, "<a href=\"x&y\">'");    defer std.testing.allocator.free(escaped);    try std.testing.expectEqualStrings("&lt;a href=&quot;x&amp;y&quot;&gt;&#39;", escaped);    var exact: [44]u8 = undefined;    const written = writeEscaped(&exact, "<a href=\"x&y\">'");    try std.testing.expectEqual(try escapedLength("<a href=\"x&y\">'"), written.len);    try std.testing.expectEqualStrings(escaped, written);}test "slug normalizes ascii heading text" {    const value = try slug(std.testing.allocator, "Fast, Robust Sites!");    defer std.testing.allocator.free(value);    try std.testing.expectEqualStrings("fast-robust-sites", value);}test "slug length and caller storage cover fallback and trailing separators" {    var normal: [17]u8 = undefined;    try std.testing.expectEqualStrings(        "fast-robust-sites",        writeSlug(&normal, "Fast, Robust Sites!--"),    );    var fallback: [7]u8 = undefined;    try std.testing.expectEqualStrings("section", writeSlug(&fallback, "!?"));    try std.testing.expectEqual(@as(usize, 7), slugLength("!?"));}

Source: lib/zen/src/root.zig:25

zig
/// HTML text and attribute escaping helpers.pub const html = @import("html.zig");

Complete caller list for html.appendAttributeEscaped

7 direct callers.

Complete caller list for html.appendEscaped

12 direct callers.

Audit

Definitions10
Public names10
Members0
Version26.7.0
Revisiondaab053ee433