Stop replacing directives with garbag on silverbullet.md
This commit is contained in:
@@ -35,6 +35,14 @@ export async function updateDirectivesOnPageCommand(arg: any) {
|
|||||||
// Collect all directives and their body replacements
|
// Collect all directives and their body replacements
|
||||||
const replacements: { fullMatch: string; text?: string }[] = [];
|
const replacements: { fullMatch: string; text?: string }[] = [];
|
||||||
|
|
||||||
|
// Sanity checking if the server gives useful responses (will not be the case on silverbullet.md)
|
||||||
|
try {
|
||||||
|
await system.invokeFunction("server", "serverPing");
|
||||||
|
} catch {
|
||||||
|
console.warn("Server not functional, not updating directives");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await replaceAsync(
|
await replaceAsync(
|
||||||
text,
|
text,
|
||||||
directiveRegex,
|
directiveRegex,
|
||||||
@@ -56,9 +64,12 @@ export async function updateDirectivesOnPageCommand(arg: any) {
|
|||||||
fullMatch,
|
fullMatch,
|
||||||
);
|
);
|
||||||
replacement.text = replacementText;
|
replacement.text = replacementText;
|
||||||
return replacementText;
|
// Return value is ignored, we're using the replacements array
|
||||||
|
return fullMatch;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return `${startInst}\n**ERROR:** ${e.message}\n${endInst}`;
|
replacement.text = `${startInst}\n**ERROR:** ${e.message}\n${endInst}`;
|
||||||
|
// Return value is ignored, we're using the replacements array
|
||||||
|
return fullMatch;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -95,6 +106,10 @@ export async function updateDirectivesOnPageCommand(arg: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function serverPing() {
|
||||||
|
return "pong";
|
||||||
|
}
|
||||||
|
|
||||||
// Called from client, running on server
|
// Called from client, running on server
|
||||||
// The text passed here is going to be a single directive block (not a full page)
|
// The text passed here is going to be a single directive block (not a full page)
|
||||||
export function serverRenderDirective(
|
export function serverRenderDirective(
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ functions:
|
|||||||
key: "Alt-q"
|
key: "Alt-q"
|
||||||
events:
|
events:
|
||||||
- editor:pageLoaded
|
- editor:pageLoaded
|
||||||
|
serverPing:
|
||||||
|
env: server
|
||||||
|
path: ./command.ts:serverPing
|
||||||
indexData:
|
indexData:
|
||||||
path: ./data.ts:indexData
|
path: ./data.ts:indexData
|
||||||
events:
|
events:
|
||||||
|
|||||||
Reference in New Issue
Block a user