silverbullet/plugs/markdown/markdown_render.test.ts

68 lines
1.8 KiB
TypeScript
Raw Normal View History

import { parse } from "$common/markdown_parser/parse_tree.ts";
import { System } from "../../lib/plugos/system.ts";
import { createSandbox } from "../../lib/plugos/sandboxes/deno_worker_sandbox.ts";
import { renderMarkdownToHtml } from "./markdown_render.ts";
import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts";
2024-07-30 23:24:17 +08:00
import { assertEquals } from "@std/assert";
2024-11-14 04:08:24 +08:00
import { fileURLToPath } from "node:url";
Deno.test("Markdown render", async () => {
const system = new System<any>("server");
await system.load(
"editor",
createSandbox(
new URL("../../dist_plug_bundle/_plug/editor.plug.js", import.meta.url),
),
);
await system.load(
"tasks",
createSandbox(
new URL("../../dist_plug_bundle/_plug/tasks.plug.js", import.meta.url),
),
);
const testFile = Deno.readTextFileSync(
2024-11-14 04:08:24 +08:00
fileURLToPath(new URL("test/example.md", import.meta.url)),
);
2024-01-24 20:34:12 +08:00
const tree = parse(extendedMarkdownLanguage, testFile);
renderMarkdownToHtml(tree, {
failOnUnknown: true,
});
// console.log("HTML", html);
await system.unloadAll();
});
2023-10-29 19:10:30 +08:00
Deno.test("Smart hard break test", () => {
const example = `**Hello**
*world!*`;
2024-01-24 20:34:12 +08:00
const tree = parse(extendedMarkdownLanguage, example);
2023-10-29 19:10:30 +08:00
const html = renderMarkdownToHtml(tree, {
failOnUnknown: true,
smartHardBreak: true,
});
2024-07-30 21:17:34 +08:00
assertEquals(
html,
`<span class="p"><strong>Hello</strong><br><em>world!</em></span>`,
);
2023-10-29 19:10:30 +08:00
const example2 = `This is going to be a text. With a new line.
And another
* and a list
* with a second item
### [[Bla]]
Url: something
Server: something else
📅 last_updated - [Release notes](release_notes_url)`;
2024-01-24 20:34:12 +08:00
const tree2 = parse(extendedMarkdownLanguage, example2);
2023-10-29 19:10:30 +08:00
const html2 = renderMarkdownToHtml(tree2, {
failOnUnknown: true,
smartHardBreak: true,
});
console.log(html2);
});