comparison markdown_converter/tests/markdown_to_html_test.c @ 231:09a96dcb2b4c hg-web

[merge] Join existing hg-web branch head
author MrJuneJune <me@mrjunejune.com>
date Sun, 02 Aug 2026 16:50:48 -0700
parents ce7f4400c2de
children
comparison
equal deleted inserted replaced
217:7ef4c9d2a72d 231:09a96dcb2b4c
1 #include "markdown_converter/markdown_to_html.h"
2
3 #include <stdio.h>
4 #include <string.h>
5
6 static int failures = 0;
7
8 static void expect_equal(const char *name, const char *markdown, const char *expected)
9 {
10 char *actual = markdown_to_html(markdown);
11 if (!actual || strcmp(actual, expected) != 0) {
12 fprintf(stderr, "%s\nexpected: %s\nactual: %s\n", name, expected, actual ? actual : "(null)");
13 failures++;
14 }
15 markdown_free(actual);
16 }
17
18 int main(void)
19 {
20 expect_equal("normal link", "[link](https://example.com)",
21 "<p><a href=\"https://example.com\">link</a></p>");
22 expect_equal("escape paragraph", "a & <b>", "<p>a &amp; &lt;b&gt;</p>");
23 expect_equal("escape raw script", "<script>alert('x')</script>",
24 "<p>&lt;script&gt;alert(&#39;x&#39;)&lt;/script&gt;</p>");
25 expect_equal("reject script link", "[open](javascript:alert)", "<p>open</p>");
26 expect_equal("reject data image", "![preview](data:image/svg+xml,test)", "<p>preview</p>");
27 expect_equal("escape link attribute", "[link](https://example.com/\"x)",
28 "<p><a href=\"https://example.com/&quot;x\">link</a></p>");
29 expect_equal("escape inline code", "`<script>`", "<p><code>&lt;script&gt;</code></p>");
30
31 return failures == 0 ? 0 : 1;
32 }