mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-25 02:32:47 +00:00
fix(markdown): keep the first image reference definition
This commit is contained in:
@@ -302,3 +302,12 @@ it("preserves angle-bracket image destinations and authored link titles during H
|
||||
' and [open](<my file.png> "<b>literal title</b>")',
|
||||
);
|
||||
});
|
||||
|
||||
it("uses the first repeated image reference definition", () => {
|
||||
const source = "![chart][image]\n\n[image]: first.png\n[image]: second.png";
|
||||
const prepared = prepareMarkdownSource(source);
|
||||
expect(prepared.images.map((image) => image.source)).toEqual(["first.png"]);
|
||||
expect(prepared.render(new Map([["first.png", "blob:first"]]))).toBe(
|
||||
"\n\n[image]: first.png\n[image]: second.png",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -74,7 +74,8 @@ export function prepareMarkdownSource(
|
||||
|
||||
const definitions = new Map<string, { url: string; title?: string | null }>();
|
||||
function definitionsIn(node: Nodes) {
|
||||
if (node.type === "definition") definitions.set(node.identifier, node);
|
||||
if (node.type === "definition" && !definitions.has(node.identifier))
|
||||
definitions.set(node.identifier, node);
|
||||
if ("children" in node) node.children.forEach(definitionsIn);
|
||||
}
|
||||
definitionsIn(getTree());
|
||||
|
||||
Reference in New Issue
Block a user