mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +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
73 lines
2.7 KiB
TypeScript
73 lines
2.7 KiB
TypeScript
import { findNodes, parser, serializer } from "../../test/editor";
|
|
import { ImageSource } from "../lib/FileHelper";
|
|
|
|
const findImageNode = (doc: ReturnType<typeof parser.parse>) => {
|
|
const imageNode = findNodes(doc?.toJSON(), "image")[0];
|
|
if (!imageNode?.attrs) {
|
|
throw new Error("Expected image node with attributes");
|
|
}
|
|
return { ...imageNode, attrs: imageNode.attrs };
|
|
};
|
|
|
|
describe("Image node source attribute round-trip", () => {
|
|
it("preserves diagrams.net source through markdown serialize → parse", () => {
|
|
const doc = parser.parse(
|
|
``
|
|
);
|
|
const imageNode = findImageNode(doc);
|
|
expect(imageNode).toBeDefined();
|
|
expect(imageNode.attrs.source).toBe(ImageSource.DiagramsNet);
|
|
});
|
|
|
|
it("serializes source tag back into markdown", () => {
|
|
const doc = parser.parse(
|
|
``
|
|
);
|
|
const markdown = serializer.serialize(doc);
|
|
expect(markdown).toContain(`source=${ImageSource.DiagramsNet}`);
|
|
});
|
|
|
|
it("round-trips a diagrams.net image without losing source", () => {
|
|
const original = ``;
|
|
const doc1 = parser.parse(original);
|
|
const md1 = serializer.serialize(doc1);
|
|
const doc2 = parser.parse(md1);
|
|
const imageNode = findImageNode(doc2);
|
|
expect(imageNode.attrs.source).toBe(ImageSource.DiagramsNet);
|
|
});
|
|
|
|
it("preserves source alongside size and title", () => {
|
|
const doc = parser.parse(
|
|
``
|
|
);
|
|
const imageNode = findImageNode(doc);
|
|
expect(imageNode.attrs.source).toBe(ImageSource.DiagramsNet);
|
|
expect(imageNode.attrs.width).toBe(100);
|
|
expect(imageNode.attrs.height).toBe(100);
|
|
});
|
|
|
|
it("does not set source for regular images", () => {
|
|
const doc = parser.parse(``);
|
|
const imageNode = findImageNode(doc);
|
|
expect(imageNode.attrs.source).toBeFalsy();
|
|
});
|
|
|
|
it("does not leak source token into title", () => {
|
|
const doc = parser.parse(
|
|
``
|
|
);
|
|
const imageNode = findImageNode(doc);
|
|
expect(imageNode.attrs.source).toBe(ImageSource.DiagramsNet);
|
|
expect(imageNode.attrs.title).not.toContain("source=");
|
|
});
|
|
|
|
it("preserves source-like text inside a caption", () => {
|
|
const doc = parser.parse(
|
|
``
|
|
);
|
|
const imageNode = findImageNode(doc);
|
|
expect(imageNode.attrs.source).toBeFalsy();
|
|
expect(imageNode.attrs.title).toBe("Caption source=example");
|
|
});
|
|
});
|