mirror of
https://github.com/outline/outline.git
synced 2026-11-25 07:04:37 +03:00
* fix: preserve diagrams.net source through API markdown round-trip Images with source: "diagrams.net" (draw.io embeds) lost their editability when updated through the API (documents.create/update with text). The markdown serializer/deserializer had no slot for the source attribute, so every round-trip through markdown stripped it, downgrading editable diagrams to static images. Encode source as a "source=<value>" token in the markdown title attribute, which already carries layoutClass and size. The token is extracted on parse and emitted on serialize, surviving the full API round-trip. * fix: address image source review feedback Authored-by: Terminus (AI Assistant) <raisalpwardana+terminus@gmail.com> * fix: narrow image test node attributes Authored-by: Terminus (AI Assistant) <raisalpwardana+terminus@gmail.com> * fix: narrow image test attributes Authored-by: Terminus (AI Assistant) <raisalpwardana+terminus@gmail.com> --------- Co-authored-by: Raisal P Wardana <IEatCodeDaily@users.noreply.github.com>
79 lines
2.9 KiB
TypeScript
79 lines
2.9 KiB
TypeScript
import { extensionManager, findNodes, schema } from "../../test/editor";
|
|
import { ImageSource } from "../lib/FileHelper";
|
|
|
|
const serializer = extensionManager.serializer();
|
|
const parser = extensionManager.parser({
|
|
schema,
|
|
plugins: extensionManager.rulePlugins,
|
|
});
|
|
|
|
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");
|
|
});
|
|
});
|