2022-12-14 19:04:20 +00:00
|
|
|
import buildMarkdown from "../../common/markdown_parser/parser.ts";
|
|
|
|
import { parse } from "../../common/markdown_parser/parse_tree.ts";
|
2022-11-01 14:01:28 +00:00
|
|
|
import { System } from "../../plugos/system.ts";
|
|
|
|
|
|
|
|
import corePlug from "../../dist_bundle/_plug/core.plug.json" assert {
|
|
|
|
type: "json",
|
|
|
|
};
|
|
|
|
import tasksPlug from "../../dist_bundle/_plug/tasks.plug.json" assert {
|
|
|
|
type: "json",
|
|
|
|
};
|
|
|
|
import { createSandbox } from "../../plugos/environments/deno_sandbox.ts";
|
2022-12-14 19:04:20 +00:00
|
|
|
import { loadMarkdownExtensions } from "../../common/markdown_parser/markdown_ext.ts";
|
2022-11-01 14:01:28 +00:00
|
|
|
import { renderMarkdownToHtml } from "./markdown_render.ts";
|
2022-12-14 19:04:20 +00:00
|
|
|
import { assertEquals } from "../../test_deps.ts";
|
2023-01-01 19:28:25 +00:00
|
|
|
import { urlToPathname } from "../../plugos/util.ts";
|
2022-11-01 14:01:28 +00:00
|
|
|
|
|
|
|
Deno.test("Markdown render", async () => {
|
|
|
|
const system = new System<any>("server");
|
|
|
|
await system.load(corePlug, createSandbox);
|
|
|
|
await system.load(tasksPlug, createSandbox);
|
|
|
|
const lang = buildMarkdown(loadMarkdownExtensions(system));
|
|
|
|
const testFile = Deno.readTextFileSync(
|
2023-01-01 19:28:25 +00:00
|
|
|
urlToPathname(new URL("test/example.md", import.meta.url)),
|
2022-11-01 14:01:28 +00:00
|
|
|
);
|
|
|
|
const tree = parse(lang, testFile);
|
|
|
|
renderMarkdownToHtml(tree, {
|
|
|
|
failOnUnknown: true,
|
|
|
|
renderFrontMatter: true,
|
|
|
|
});
|
|
|
|
// console.log("HTML", html);
|
|
|
|
});
|
|
|
|
|
2023-02-23 14:33:51 +00:00
|
|
|
Deno.test("Smart hard break test", async () => {
|
2022-11-01 14:01:28 +00:00
|
|
|
const example = `**Hello**
|
|
|
|
*world!*`;
|
|
|
|
const lang = buildMarkdown([]);
|
|
|
|
const tree = parse(lang, example);
|
2023-02-23 14:33:51 +00:00
|
|
|
const html = await renderMarkdownToHtml(tree, {
|
2022-11-01 14:01:28 +00:00
|
|
|
failOnUnknown: true,
|
|
|
|
smartHardBreak: true,
|
|
|
|
});
|
|
|
|
assertEquals(
|
|
|
|
html,
|
|
|
|
`<p><strong>Hello</strong><br/><em>world!</em></p>`,
|
|
|
|
);
|
|
|
|
});
|