feat: render LaTeX, custom HTML and diagrams in the transcript (#19)
This commit was merged in pull request #19.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
fenceAsciiArt,
|
||||
inferLanguage,
|
||||
labelCodeFences,
|
||||
mapOutsideCodeSpans,
|
||||
normalizeFenceLabels,
|
||||
promoteStandaloneCodeSpans,
|
||||
repairCodeBlocks,
|
||||
restoreUrlLinks,
|
||||
@@ -416,3 +419,60 @@ describe("labelCodeFences", () => {
|
||||
expect(labelCodeFences(" ```\n ls\n ```")).toContain(" ```bash");
|
||||
});
|
||||
});
|
||||
|
||||
describe("mapOutsideCodeSpans", () => {
|
||||
it("applies the transform everywhere a span is not", () => {
|
||||
expect(mapOutsideCodeSpans("a `b` c", (text) => text.toUpperCase())).toBe("A `b` C");
|
||||
});
|
||||
|
||||
it("matches a delimiter of the same length only", () => {
|
||||
// A single-backtick span inside a double-backtick span is content, not a
|
||||
// closer, so the inner one is left exactly as written.
|
||||
expect(mapOutsideCodeSpans("`` `a` ``", (text) => text.toUpperCase())).toBe("`` `a` ``");
|
||||
});
|
||||
|
||||
it("treats an unclosed run as text and carries on after it", () => {
|
||||
expect(mapOutsideCodeSpans("a ` b", (text) => text.toUpperCase())).toBe("A ` B");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeFenceLabels", () => {
|
||||
it("names a language that resolves in place of one that does not", () => {
|
||||
expect(normalizeFenceLabels("```console\nls\n```")).toBe("```bash\nls\n```");
|
||||
});
|
||||
|
||||
it("drops a label that carries no information", () => {
|
||||
expect(normalizeFenceLabels("```text\nplain\n```")).toBe("```\nplain\n```");
|
||||
});
|
||||
|
||||
it("leaves a language the model chose alone", () => {
|
||||
const input = "```rust\nfn main() {}\n```";
|
||||
expect(normalizeFenceLabels(input)).toBe(input);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fenceAsciiArt", () => {
|
||||
it("fences a tree so its columns stay monospaced", () => {
|
||||
expect(fenceAsciiArt("src/\n├── a.ts\n└── b.ts")).toBe("```\nsrc/\n├── a.ts\n└── b.ts\n```");
|
||||
});
|
||||
|
||||
it("fences an ASCII table drawn with borders", () => {
|
||||
const art = "+---+---+\n| a | b |\n+---+---+";
|
||||
expect(fenceAsciiArt(art)).toBe("```\n" + art + "\n```");
|
||||
});
|
||||
|
||||
it("leaves a real GFM table to the table renderer", () => {
|
||||
const table = "| a | b |\n| --- | --- |\n| 1 | 2 |";
|
||||
expect(fenceAsciiArt(table)).toBe(table);
|
||||
});
|
||||
|
||||
it("leaves prose that contains one pipe alone", () => {
|
||||
const prose = "Here is what it does:\n| a | b |";
|
||||
expect(fenceAsciiArt(prose)).toBe(prose);
|
||||
});
|
||||
|
||||
it("leaves a diagram that is already fenced alone", () => {
|
||||
const fenced = "```\n├── a.ts\n└── b.ts\n```";
|
||||
expect(fenceAsciiArt(fenced)).toBe(fenced);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user