mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
- Serialize code fences longer than any backtick run in the content, so content lines cannot terminate the fence early on reparse - Reduce the fence info string and language attribute to a single safe token when parsing and serializing - Share the markdown parser and serializer through the editor test helper
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import type { JSONNode } from "../../test/editor";
|
|
import { findNodes, parser } from "../../test/editor";
|
|
|
|
const parseToJSON = (markdown: string): JSONNode | undefined =>
|
|
parser.parse(markdown)?.toJSON();
|
|
|
|
describe("math markdown rules", () => {
|
|
it("parses inline math", () => {
|
|
const doc = parseToJSON("before $x + y$ after");
|
|
const nodes = findNodes(doc, "math_inline");
|
|
|
|
expect(nodes).toHaveLength(1);
|
|
expect(nodes[0].content?.[0].text).toBe("x + y");
|
|
});
|
|
|
|
it("parses block math with closing delimiter on its own line", () => {
|
|
const doc = parseToJSON("$$\na = b\n$$\n\nparagraph after");
|
|
const nodes = findNodes(doc, "math_block");
|
|
|
|
expect(nodes).toHaveLength(1);
|
|
expect(nodes[0].content?.[0].text).toContain("a = b");
|
|
expect(findNodes(doc, "paragraph")).toHaveLength(1);
|
|
});
|
|
|
|
it("parses block math with closing delimiter at the end of a content line", () => {
|
|
const doc = parseToJSON("$$\na = b\nc = d$$\n\nparagraph after");
|
|
const blocks = findNodes(doc, "math_block");
|
|
|
|
expect(blocks).toHaveLength(1);
|
|
expect(blocks[0].content?.[0].text).toContain("a = b");
|
|
expect(blocks[0].content?.[0].text).toContain("c = d");
|
|
|
|
// The paragraph following the block must not be swallowed into the math
|
|
const paragraphs = findNodes(doc, "paragraph");
|
|
expect(paragraphs).toHaveLength(1);
|
|
expect(blocks[0].content?.[0].text).not.toContain("paragraph after");
|
|
});
|
|
|
|
it("leaves unclosed inline math as plain text", () => {
|
|
const doc = parseToJSON("price is $5 and rising");
|
|
|
|
expect(findNodes(doc, "math_inline")).toHaveLength(0);
|
|
expect(findNodes(doc, "math_block")).toHaveLength(0);
|
|
});
|
|
});
|