Skip to documentation
SLOP

tiny.markdown.parseBlockType

Reference tiny.markdown parseBlockType

Defined in block.

Called byCallstest sourcelib.markdown.src.blocktest: parseType blockquotetest sourcelib.markdown.src.blocktest: parseType bullet listtest sourcelib.markdown.src.blocktest: parseType headingtest sourcelib.markdown.src.blocktest: parseType horizontal ruletest sourcelib.markdown.src.blocktest: parseType numbered listtest sourcelib.markdown.src.blocktest: parseType paragraphprivate sourcelib.markdown.src.blockmarkdownIndentprivate sourcelib.markdown.src.blocktrimLeftblockparseType
Static calls · unresolved targets: 1 · external targets: 0.

Source

Source: lib/markdown/src/block.zig:31

zig
pub fn parseType(line: []const u8) Parsed {    const indent = markdownIndent(line);    const trimmed = trimLeft(line, " \t");    if (trimmed.len == 0) {        return .{ .block_type = .paragraph, .content = "", .number = null, .indent = indent };    }    if (trimmed.len >= 3 and (std.mem.startsWith(u8, trimmed, "---") or std.mem.startsWith(u8, trimmed, "***") or std.mem.startsWith(u8, trimmed, "___"))) {        var all_same = true;        const first = trimmed[0];        for (trimmed) |c| {            if (c != first and c != ' ') {                all_same = false;                break;            }        }        if (all_same) {            return .{ .block_type = .horizontal_rule, .content = "", .number = null, .indent = indent };        }    }    if (std.mem.startsWith(u8, trimmed, "#### ")) {        return .{ .block_type = .heading4, .content = trimmed[5..], .number = null, .indent = indent };    }    if (std.mem.startsWith(u8, trimmed, "### ")) {        return .{ .block_type = .heading3, .content = trimmed[4..], .number = null, .indent = indent };    }    if (std.mem.startsWith(u8, trimmed, "## ")) {        return .{ .block_type = .heading2, .content = trimmed[3..], .number = null, .indent = indent };    }    if (std.mem.startsWith(u8, trimmed, "# ")) {        return .{ .block_type = .heading1, .content = trimmed[2..], .number = null, .indent = indent };    }    if (std.mem.startsWith(u8, trimmed, "> ")) {        return .{ .block_type = .blockquote, .content = trimmed[2..], .number = null, .indent = indent };    }    if (std.mem.startsWith(u8, trimmed, ">")) {        return .{ .block_type = .blockquote, .content = trimmed[1..], .number = null, .indent = indent };    }    if (trimmed.len >= 2 and (trimmed[0] == '-' or trimmed[0] == '*' or trimmed[0] == '+') and trimmed[1] == ' ') {        return .{ .block_type = .bullet_list, .content = trimmed[2..], .number = null, .indent = indent };    }    if (trimmed.len >= 3) {        var num_end: usize = 0;        while (num_end < trimmed.len and trimmed[num_end] >= '0' and trimmed[num_end] <= '9') {            num_end += 1;        }        if (num_end > 0 and num_end < trimmed.len and trimmed[num_end] == '.' and num_end + 1 < trimmed.len and trimmed[num_end + 1] == ' ') {            const num = std.fmt.parseInt(u16, trimmed[0..num_end], 10) catch 1;            return .{ .block_type = .numbered_list, .content = trimmed[num_end + 2 ..], .number = num, .indent = indent };        }    }    if (std.mem.startsWith(u8, trimmed, "```")) {        return .{ .block_type = .code_block, .content = trimmed[3..], .number = null, .indent = indent };    }    return .{ .block_type = .paragraph, .content = trimmed, .number = null, .indent = indent };}

Source: lib/markdown/src/root.zig:16

zig
pub const parseBlockType = block.parseType;

Audit

Definitions1
Public names2
Members0
Version26.7.0
Revisiondaab053ee433