mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-24 21:41:30 +08:00
feat(import/export): import reference links
This commit is contained in:
parent
320439333d
commit
4f22850ea9
@ -238,4 +238,10 @@ describe("Markdown export", () => {
|
||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||
});
|
||||
|
||||
it("exports reference links as normal links", () => {
|
||||
const html = /*html*/`<p><a class="reference-link" href="../../Canvas.html">Canvas</a></p>`;
|
||||
const expected = `[Canvas](../../Canvas.html)`;
|
||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -145,4 +145,16 @@ second line 2</code></pre><ul><li>Hello</li><li>world</li></ul><ol><li>Hello</li
|
||||
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it("supports normal links", () => {
|
||||
const input = `[Google](https://www.google.com)`;
|
||||
const expected = /*html*/`<p><a href="https://www.google.com">Google</a></p>`;
|
||||
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it("imports back to reference links", () => {
|
||||
const input = `[Canvas](../../Canvas.html)`;
|
||||
const expected = /*html*/`<p><a class="reference-link" href="../../Canvas.html">Canvas</a></p>`;
|
||||
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -64,6 +64,17 @@ class CustomMarkdownRenderer extends Renderer {
|
||||
return `<blockquote>${body}</blockquote>`;
|
||||
}
|
||||
|
||||
link(data: Tokens.Link): string {
|
||||
let html = super.link(data);
|
||||
|
||||
// Rewrite local/relative links back to reference links.
|
||||
if (data.href.indexOf("://") === -1) {
|
||||
html = html.replace(/^<a /, `<a class="reference-link" `);
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const renderer = new CustomMarkdownRenderer({ async: false });
|
||||
|
Loading…
x
Reference in New Issue
Block a user