mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
* fix: Resolve Slab cross-links and import Slab-hosted attachments Slab exports links between posts as absolute URLs and file attachments as signed links, so both stayed pointing at Slab after import. Post links are now matched to imported documents by slug (or by label for id-only mention links) and Slab-hosted file links become attachments that are re-hosted. Also fixes concurrent mention transforms assigning different ids to the same not-yet-imported document. * fix: Address review feedback on Slab link and file conversion Prefer exact slug matches and leave ambiguous slugs unresolved, convert file links in headings, and keep a toggle's leading text block so its attachments are still converted.
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { replaceMarkdownLinks } from "./markdown";
|
|
|
|
describe("replaceMarkdownLinks", () => {
|
|
const toUpper = (href: string) => href.toUpperCase();
|
|
|
|
it("replaces the destination of a link, leaving its label", () => {
|
|
expect(replaceMarkdownLinks("see [other](./other.md)", toUpper)).toBe(
|
|
"see [other](./OTHER.MD)"
|
|
);
|
|
});
|
|
|
|
it("passes the label of a link and an image", () => {
|
|
const labels: string[] = [];
|
|
replaceMarkdownLinks("[one](a.md) and ", (_href, label) => {
|
|
labels.push(label);
|
|
return undefined;
|
|
});
|
|
expect(labels).toEqual(["one", "two"]);
|
|
});
|
|
|
|
it("replaces the destination of an image", () => {
|
|
expect(replaceMarkdownLinks("", toUpper)).toBe(
|
|
""
|
|
);
|
|
});
|
|
|
|
it("preserves a link title", () => {
|
|
expect(
|
|
replaceMarkdownLinks('', toUpper)
|
|
).toBe('');
|
|
});
|
|
|
|
it("understands an angle bracketed destination", () => {
|
|
expect(replaceMarkdownLinks("", toUpper)).toBe(
|
|
""
|
|
);
|
|
});
|
|
|
|
it("preserves a title after an angle bracketed destination", () => {
|
|
expect(replaceMarkdownLinks('[x](<my doc.md> "Title")', toUpper)).toBe(
|
|
'[x](MY DOC.MD "Title")'
|
|
);
|
|
});
|
|
|
|
it("leaves a link alone when the replacer returns undefined", () => {
|
|
expect(replaceMarkdownLinks("[x](./y.md)", () => undefined)).toBe(
|
|
"[x](./y.md)"
|
|
);
|
|
});
|
|
|
|
it("leaves an unterminated angle bracket alone", () => {
|
|
expect(replaceMarkdownLinks("[x](<unclosed)", toUpper)).toBe(
|
|
"[x](<unclosed)"
|
|
);
|
|
});
|
|
|
|
it("replaces every link in the text", () => {
|
|
expect(replaceMarkdownLinks("[a](one.md) and [b](two.md)", toUpper)).toBe(
|
|
"[a](ONE.MD) and [b](TWO.MD)"
|
|
);
|
|
});
|
|
});
|