This commit is contained in:
parent
84cc6cf82b
commit
6418dbb7e2
5
.changeset/thick-worms-peel.md
Normal file
5
.changeset/thick-worms-peel.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'@portaljs/remark-wiki-link': minor
|
||||
---
|
||||
|
||||
Parse note embeds as regular wiki links (until we add proper support for note embeds).
|
||||
@ -125,6 +125,16 @@ function fromMarkdown(opts: FromMarkdownOptions = {}) {
|
||||
if (isEmbed) {
|
||||
const [isSupportedFormat, format] = isSupportedFileFormat(target);
|
||||
if (!isSupportedFormat) {
|
||||
// Temporarily render note transclusion as a regular wiki link
|
||||
if (!format) {
|
||||
wikiLink.data.hName = "a";
|
||||
wikiLink.data.hProperties = {
|
||||
className: classNames + " " + "transclusion",
|
||||
href: hrefTemplate(link) + headingId,
|
||||
};
|
||||
wikiLink.data.hChildren = [{ type: "text", value: displayName }];
|
||||
|
||||
} else {
|
||||
wikiLink.data.hName = "p";
|
||||
wikiLink.data.hChildren = [
|
||||
{
|
||||
@ -132,6 +142,7 @@ function fromMarkdown(opts: FromMarkdownOptions = {}) {
|
||||
value: `![[${target}]]`,
|
||||
},
|
||||
];
|
||||
}
|
||||
} else if (format === "pdf") {
|
||||
wikiLink.data.hName = "iframe";
|
||||
wikiLink.data.hProperties = {
|
||||
|
||||
@ -108,7 +108,16 @@ function html(opts: HtmlOptions = {}) {
|
||||
if (isEmbed) {
|
||||
const [isSupportedFormat, format] = isSupportedFileFormat(target);
|
||||
if (!isSupportedFormat) {
|
||||
// Temporarily render note transclusion as a regular wiki link
|
||||
if (!format) {
|
||||
this.tag(
|
||||
`<a href="${hrefTemplate(link + headingId)}" class="${classNames} transclusion">`
|
||||
);
|
||||
this.raw(displayName);
|
||||
this.tag("</a>");
|
||||
} else {
|
||||
this.raw(`![[${target}]]`);
|
||||
}
|
||||
} else if (format === "pdf") {
|
||||
this.tag(
|
||||
`<iframe width="100%" src="${hrefTemplate(
|
||||
|
||||
@ -309,4 +309,16 @@ describe("micromark-extension-wiki-link", () => {
|
||||
expect(serialized).toBe('<p><a href="/" class="internal">/index</a></p>');
|
||||
});
|
||||
});
|
||||
|
||||
describe("transclusions", () => {
|
||||
test("parsers a transclusion as a regular wiki link", () => {
|
||||
const serialized = micromark("![[Some Page]]", "ascii", {
|
||||
extensions: [syntax()],
|
||||
htmlExtensions: [html() as any], // TODO type fix
|
||||
});
|
||||
expect(serialized).toBe(
|
||||
'<p><a href="Some Page" class="internal new transclusion">Some Page</a></p>'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -535,4 +535,28 @@ describe("remark-wiki-link", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("transclusions", () => {
|
||||
test("replaces a transclusion with a regular wiki link", () => {
|
||||
const processor = unified().use(markdown).use(wikiLinkPlugin);
|
||||
|
||||
let ast = processor.parse("![[Some Page]]");
|
||||
ast = processor.runSync(ast);
|
||||
|
||||
expect(select("wikiLink", ast)).not.toEqual(null);
|
||||
|
||||
visit(ast, "wikiLink", (node: Node) => {
|
||||
expect(node.data?.isEmbed).toEqual(true);
|
||||
expect(node.data?.exists).toEqual(false);
|
||||
expect(node.data?.permalink).toEqual("Some Page");
|
||||
expect(node.data?.alias).toEqual(null);
|
||||
expect(node.data?.hName).toEqual("a");
|
||||
expect((node.data?.hProperties as any).className).toEqual(
|
||||
"internal new transclusion"
|
||||
);
|
||||
expect((node.data?.hProperties as any).href).toEqual("Some Page");
|
||||
expect((node.data?.hChildren as any)[0].value).toEqual("Some Page");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user