const std = @import("std"); const allocator = std.testing.allocator; const zmd = @import("../root.zig"); const expectEqualStrings = std.testing.expectEqualStrings; test "h1" { const html = \\ \\ \\ \\ \\ \\ \\
\\

Header

\\
\\ \\ \\ ; const md = \\# Header ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "h2" { const html = \\ \\ \\ \\ \\ \\ \\
\\

Header

\\
\\ \\ \\ ; const md = \\## Header ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "h3" { const html = \\ \\ \\ \\ \\ \\ \\
\\

Header

\\
\\ \\ \\ ; const md = \\### Header ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "h4" { const html = \\ \\ \\ \\ \\ \\ \\
\\

Header

\\
\\ \\ \\ ; const md = \\#### Header ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "h5" { const html = \\ \\ \\ \\ \\ \\ \\
\\
Header
\\
\\ \\ \\ ; const md = \\##### Header ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "h6" { const html = \\ \\ \\ \\ \\ \\ \\
\\
Header
\\
\\ \\ \\ ; const md = \\###### Header ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "bold (dangling)" { const html = \\ \\ \\ \\ \\ \\ \\
\\

bold

\\
\\ \\ \\ ; const md = \\**bold** ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "bold (embedded)" { const html = \\ \\ \\ \\ \\ \\ \\
\\

some bold text

\\
\\ \\ \\ ; const md = \\some **bold** text ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "italic (dangling)" { const html = \\ \\ \\ \\ \\ \\ \\
\\

italic

\\
\\ \\ \\ ; const md = \\_italic_ ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "italic (embedded)" { const html = \\ \\ \\ \\ \\ \\ \\
\\

some italic text

\\
\\ \\ \\ ; const md = \\some _italic_ text ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "italic with asterisks (dangling)" { const html = \\ \\ \\ \\ \\ \\ \\
\\

italic

\\
\\ \\ \\ ; const md = \\*italic* ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "italic with asterisks (embedded)" { const html = \\ \\ \\ \\ \\ \\ \\
\\

some italic text

\\
\\ \\ \\ ; const md = \\some *italic* text ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "code (dangling)" { const html = \\ \\ \\ \\ \\ \\ \\
\\

code

\\
\\ \\ \\ ; const md = \\`code` ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "code (embedded)" { const html = \\ \\ \\ \\ \\ \\ \\
\\

some code text

\\
\\ \\ \\ ; const md = \\some `code` text ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "block" { const html = \\ \\ \\ \\ \\ \\ \\
\\
        \\
        \\if (1 < 10) {
        \\   return "1 is less than 10";
        \\}
        \\
        \\
\\
\\ \\ \\ ; const md = \\```zig \\if (1 < 10) { \\ return "1 is less than 10"; \\} \\``` ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "image" { const html = \\ \\ \\ \\ \\ \\ \\
\\

\\
\\ \\ \\ ; const md = \\![image title](https://example.com/image.png) ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "link" { const html = \\ \\ \\ \\ \\ \\ \\
\\

link title

\\
\\ \\ \\ ; const md = \\[link title](https://example.com/) ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "dangling brackets (no href)" { const html = \\ \\ \\ \\ \\ \\ \\
\\

index [0] of array

\\
\\ \\ \\ ; const md = \\index [0] of array ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "passthrough ref ({{ ... }})" { const html = \\ \\ \\ \\ \\ \\ \\
\\

value is {{ $.user_name[0] < limit }} today

\\
\\ \\ \\ ; const md = \\value is {{ $.user_name[0] < limit }} today ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "link with passthrough refs in title and href" { // A link whose title and href are `{{ ... }}` refs must still parse as a link, with the refs // passed through verbatim for a downstream consumer to resolve. const html = \\ \\ \\ \\ \\ \\ \\
\\

{{$.title}}

\\
\\ \\ \\ ; const md = \\[{{$.title}}]({{$.url}}) ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "nested image inside link title" { const html = \\ \\ \\ \\ \\ \\ \\
\\

\\
\\ \\ \\ ; const md = \\[![alt](https://example.com/i.png)](https://example.com/) ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "paragraph" { const html = \\ \\ \\ \\ \\ \\ \\
\\

a title

\\

a paragraph

\\
\\ \\ \\ ; const md = \\# a title \\ \\a paragraph ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "unordered list (+)" { const html = \\ \\ \\ \\ \\ \\ \\
\\ \\
\\ \\ \\ ; const md = \\+ list item 1 \\+ list item 2 \\+ list item 3 ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "unordered list (-)" { const html = \\ \\ \\ \\ \\ \\ \\
\\ \\
\\ \\ \\ ; const md = \\- list item 1 \\- list item 2 \\- list item 3 ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "unordered list (*)" { const html = \\ \\ \\ \\ \\ \\ \\
\\ \\
\\ \\ \\ ; const md = \\* list item 1 \\* list item 2 \\* list item 3 ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "ordered list (1., 1., 1.)" { const html = \\ \\ \\ \\ \\ \\ \\
\\
    \\
  1. list item 1
  2. \\
  3. list item 2
  4. \\
  5. list item 3
  6. \\
\\
\\ \\ \\ ; const md = \\1. list item 1 \\1. list item 2 \\1. list item 3 ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "ordered list (1., 2., 3.)" { const html = \\ \\ \\ \\ \\ \\ \\
\\
    \\
  1. list item 1
  2. \\
  3. list item 2
  4. \\
  5. list item 3
  6. \\
\\
\\ \\ \\ ; const md = \\1. list item 1 \\2. list item 2 \\3. list item 3 ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "list with embedded elements" { const html = \\ \\ \\ \\ \\ \\ \\
\\ \\
\\ \\ \\ ; const md = \\* list item with [my link](https://www.example.com/) \\* list item with ![my image](https://www.example.com/image.png) \\* list item with **bold** and _italic_ text ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); } test "nested mixed ordered and unordered lists" { const html = \\ \\ \\ \\ \\ \\ \\
\\
    \\
  1. first
  2. \\
  3. second \\
      \\
    • bullet a
    • \\
    • bullet b
    • \\
    \\
  4. \\
  5. third
  6. \\
\\
\\ \\ \\ ; const md = \\1. first \\2. second \\ * bullet a \\ * bullet b \\3. third ; const parsed = try zmd.parseAlloc(allocator, md, .{}); defer allocator.free(parsed); try expectEqualStrings(html, parsed); }