Rewrite page references in federated pages
This commit is contained in:
@@ -55,6 +55,24 @@ export function rewritePageRefs(tree: ParseTree, containerPageName: string) {
|
||||
|
||||
return true;
|
||||
}
|
||||
if (n.type === "FencedCode") {
|
||||
const codeInfo = findNodeOfType(n, "CodeInfo");
|
||||
if (!codeInfo) {
|
||||
return true;
|
||||
}
|
||||
if (!["query", "template"].includes(codeInfo.children![0].text!)) {
|
||||
return true;
|
||||
}
|
||||
const codeText = findNodeOfType(n, "CodeText");
|
||||
if (!codeText) {
|
||||
return true;
|
||||
}
|
||||
let bodyText = codeText.children![0].text!;
|
||||
bodyText = rewritePageRefsInString(bodyText, containerPageName);
|
||||
codeText.children![0].text = bodyText;
|
||||
|
||||
return true;
|
||||
}
|
||||
if (n.type === "WikiLinkPage") {
|
||||
n.children![0].text = resolvePath(
|
||||
containerPageName,
|
||||
@@ -67,6 +85,15 @@ export function rewritePageRefs(tree: ParseTree, containerPageName: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function rewritePageRefsInString(
|
||||
bodyText: string,
|
||||
containerPageName: string,
|
||||
) {
|
||||
return bodyText.replaceAll(/\[\[(.+)\]\]/g, (_match, pageRefName) => {
|
||||
return `[[${resolvePath(containerPageName, pageRefName)}]]`;
|
||||
});
|
||||
}
|
||||
|
||||
export function cleanPageRef(pageRef: string) {
|
||||
if (pageRef.startsWith("[[") && pageRef.endsWith("]]")) {
|
||||
return pageRef.slice(2, -2);
|
||||
|
||||
Reference in New Issue
Block a user