view markdown_converter/tests/markdown_to_html_test.c @ 268:f7b1188d5fb1

support repo rules Copilot bundle path Match both +_repo_rules2+ and +http_archive+ Copilot CLI repository layouts during deployment and production startup. Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Fri, 07 Aug 2026 13:02:41 -0700
parents ce7f4400c2de
children
line wrap: on
line source

#include "markdown_converter/markdown_to_html.h"

#include <stdio.h>
#include <string.h>

static int failures = 0;

static void expect_equal(const char *name, const char *markdown, const char *expected)
{
  char *actual = markdown_to_html(markdown);
  if (!actual || strcmp(actual, expected) != 0) {
    fprintf(stderr, "%s\nexpected: %s\nactual:   %s\n", name, expected, actual ? actual : "(null)");
    failures++;
  }
  markdown_free(actual);
}

int main(void)
{
  expect_equal("normal link", "[link](https://example.com)",
               "<p><a href=\"https://example.com\">link</a></p>");
  expect_equal("escape paragraph", "a & <b>", "<p>a &amp; &lt;b&gt;</p>");
  expect_equal("escape raw script", "<script>alert('x')</script>",
               "<p>&lt;script&gt;alert(&#39;x&#39;)&lt;/script&gt;</p>");
  expect_equal("reject script link", "[open](javascript:alert)", "<p>open</p>");
  expect_equal("reject data image", "![preview](data:image/svg+xml,test)", "<p>preview</p>");
  expect_equal("escape link attribute", "[link](https://example.com/\"x)",
               "<p><a href=\"https://example.com/&quot;x\">link</a></p>");
  expect_equal("escape inline code", "`<script>`", "<p><code>&lt;script&gt;</code></p>");

  return failures == 0 ? 0 : 1;
}