const std = @import("std"); const Writer = std.Io.Writer; const allocator = std.testing.allocator; const zmd = @import("../root.zig"); const Node = @import("../Parser.zig").Node; const expectEqualStrings = std.testing.expectEqualStrings; test "parse markdown and translate to HTML" { const html = \\ \\ \\ \\ \\ \\ \\
\\

Header

\\

Sub-header

\\

Sub-sub-header

\\

some text in bold and italic

\\

a paragraph

\\

a link: my link

\\

an image:

\\
        \\
        \\if (1 < 10) {
        \\    std.debug.print("1 is < 10 !");
        \\}
        \\
        \\
\\

some more text with a code fragment

\\
\\ \\ \\ ; const md = \\# Header \\## Sub-header \\### Sub-sub-header \\ \\some text in **bold** and _italic_ \\ \\a paragraph \\ \\a link: [my link](https://ziglang.org/) \\ \\an image: ![jetzig logo](https://www.jetzig.dev/jetzig.png) \\ \\```zig \\if (1 < 10) { \\ std.debug.print("1 is < 10 !"); \\} \\``` \\some more text with a `code` fragment \\ ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "parse content without trailing linebreak before eof" { const html = \\ \\ \\ \\ \\ \\ \\
\\

Header

\\
\\ \\ \\ ; const md = \\# Header ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "parse paragraph leading with a token" { const html = \\ \\ \\ \\ \\ \\ \\
\\

Header

\\

bold text at the start of a paragraph

\\
\\ \\ \\ ; const md = \\# Header \\ \\**bold** text at the start of a paragraph ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "parse indented list" { const html = \\ \\ \\ \\ \\ \\ \\
\\ \\
\\ \\ \\ ; const md = \\ * foo \\ * bar \\ * baz ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "parse underscores in code element" { const html = \\ \\ \\ \\ \\ \\ \\
\\ \\
\\ \\ \\ ; const md = \\* `foo_bar` \\* `baz_qux` \\* `quux_corge` ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "parse parentheses in paragraph" { const html = \\ \\ \\ \\ \\ \\ \\
\\

some text (with parentheses) in a paragraph

\\
\\ \\ \\ ; const md = \\some text (with parentheses) in a paragraph ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "parse underscore in link" { const html = \\ \\ \\ \\ \\ \\ \\
\\

a link to here_doc with italics and bold

\\
\\ \\ \\ ; const md = \\a _link_ to [here_doc](https://en.wikipedia.org/wiki/Here_document) with _italics_ and **bold** ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "parse underscores in block" { const html = \\ \\ \\ \\ \\ \\ \\
\\
        \\
        \\if (foo_bar_baz) return true;
        \\
        \\
\\
\\ \\ \\ ; const md = \\```zig \\if (foo_bar_baz) return true; \\``` ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "parse repeated whitespace" { // Used to be really slow const parsed = try zmd.parseAlloc(allocator, " " ** 40_000, .{}); allocator.free(parsed); } fn newH1(writer: *Writer, node: Node) Writer.Error![]const u8 { _ = node; try writer.writeAll(""); return \\ \\ ; } fn newRoot(writer: *Writer, node: Node) Writer.Error![]const u8 { _ = writer; _ = node; return ""; } test "custom handler func" { const html = \\Hello \\ ; const md = "# Hello"; const parsed = try zmd.parseAlloc(allocator, md, .{ .h1 = newH1, .root = newRoot, }); defer allocator.free(parsed); try expectEqualStrings(html, parsed); }