37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
import { pathToFileURL } from "node:url";
|
|
const { defaultMarkdownParser: P, defaultMarkdownSerializer: S } = await import(pathToFileURL(process.argv[2]).href);
|
|
const cases = {
|
|
table: "| a | b |\n|---|---|\n| 1 | 2 |\n",
|
|
htmlBlock: "<div>hello</div>\n\ntext\n",
|
|
htmlInline: "a <b>bold</b> c\n",
|
|
scriptBlock: "<script>alert(1)</script>\n",
|
|
rule: "above\n\n---\n\nbelow\n",
|
|
dashList: "- one\n- two\n",
|
|
plusList: "+ one\n+ two\n",
|
|
loose: "- one\n\n- two\n",
|
|
orderedStart: "3. three\n4. four\n",
|
|
wrapped: "line one\nline two\n",
|
|
hardbreak: "a \nb\n",
|
|
setext: "Title\n=====\n",
|
|
tilde: "~~~js\nx\n~~~\n",
|
|
indentedCode: " code\n",
|
|
refLink: "[a][1]\n\n[1]: http://x.test\n",
|
|
autolink: "<http://x.test>\n",
|
|
bareUrl: "see http://x.test now\n",
|
|
strike: "~~gone~~\n",
|
|
task: "- [ ] todo\n- [x] done\n",
|
|
image: "\n",
|
|
jsLink: "[x](javascript:alert(1))\n",
|
|
entity: "a & b < c\n",
|
|
underscores: "snake_case_word and _em_\n",
|
|
star: "2 * 3 * 4\n",
|
|
hashStart: "\\# not heading\n",
|
|
frontmatter: "---\ntitle: x\n---\n\nbody\n",
|
|
blank3: "a\n\n\n\nb\n",
|
|
crlf: "a\r\nb\r\n",
|
|
};
|
|
for (const [k, v] of Object.entries(cases)) {
|
|
let out; try { out = S.serialize(P.parse(v)); } catch (e) { out = "THROWS " + e.message; }
|
|
console.log((out === v ? "SAME " : "CHANGED") + " " + k.padEnd(13) + JSON.stringify(v) + (out === v ? "" : " -> " + JSON.stringify(out)));
|
|
}
|