import markdownHighlighter from "../src/giallo-markdown.js"; const DEFAULT_OPTIONS = { themeLight: "github-light", themeDark: "github-dark", }; const SNIPPET_JS = ` import { readFile } from "node:fs"; /** * Print contents of a file. */ export default async function printFile(path) { const text = await readFile(path, "utf-8"); console.log(text); } `; const RENDERED_JS = `

import { readFile } from "node:fs";

/**
 * Print contents of a file.
 */
export default async function printFile(path) {
  const text = await readFile(path, "utf-8");
  console.log(text);
}
`; const RENDERED_JS_PLAIN = `

import { readFile } from "node:fs";

/**
 * Print contents of a file.
 */
export default async function printFile(path) {
  const text = await readFile(path, "utf-8");
  console.log(text);
}
`; const SNIPPET_PY = `print(f"{my_fn('')}")`; test("renders Javascript code as arbitrary HTML", () => { const configuredHighlighter = markdownHighlighter(DEFAULT_OPTIONS); const rendered = configuredHighlighter(SNIPPET_JS, "javascript"); expect(rendered).toContain("<"); }); test("renders Javascript code as expected HTML", () => { const configuredHighlighter = markdownHighlighter(DEFAULT_OPTIONS); const rendered = configuredHighlighter(SNIPPET_JS, "javascript"); expect(rendered).toEqual(RENDERED_JS); }); test("treats unknown language as plain", () => { const configuredHighlighter = markdownHighlighter(DEFAULT_OPTIONS); const rendered = configuredHighlighter(SNIPPET_JS, "piedpiperscript"); expect(rendered).toEqual(RENDERED_JS_PLAIN); }); test("escapes embedded HTML", () => { const configuredHighlighter = markdownHighlighter(DEFAULT_OPTIONS); const rendered = configuredHighlighter(SNIPPET_PY, "python"); expect(rendered).toContain("<a>"); });