Template syntax refactor
This commit is contained in:
@@ -187,18 +187,35 @@ functions:
|
||||
path: "./template.ts:insertTemplateText"
|
||||
slashCommand:
|
||||
name: include
|
||||
description: Include another page
|
||||
value: |
|
||||
<!-- #include "|^|" -->
|
||||
<!-- #include [[|^|]] -->
|
||||
|
||||
<!-- /include -->
|
||||
insertInlineTemplate:
|
||||
insertInjectTemplate:
|
||||
path: "./template.ts:insertTemplateText"
|
||||
slashCommand:
|
||||
name: inline-template
|
||||
name: inject
|
||||
description: Inject template
|
||||
value: |
|
||||
<!-- #template "|^|" {} -->
|
||||
<!-- #inject [[|^|]] {} -->
|
||||
|
||||
<!-- /template -->
|
||||
<!-- /inject -->
|
||||
insertInjectCleanTemplate:
|
||||
path: "./template.ts:insertTemplateText"
|
||||
slashCommand:
|
||||
name: inject-clean
|
||||
description: Inject template clean
|
||||
value: |
|
||||
<!-- #inject-clean [[|^|]] {} -->
|
||||
|
||||
<!-- /inject-clean -->
|
||||
insertHRTemplate:
|
||||
path: "./template.ts:insertTemplateText"
|
||||
slashCommand:
|
||||
name: hr
|
||||
description: Insert a horizontal rule
|
||||
value: "---"
|
||||
quickNoteCommand:
|
||||
path: ./template.ts:quickNoteCommand
|
||||
command:
|
||||
|
||||
@@ -48,6 +48,7 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
|
||||
console.log("Now indexing", name);
|
||||
let pageMeta = extractMeta(tree);
|
||||
if (Object.keys(pageMeta).length > 0) {
|
||||
console.log("Extracted page meta data", pageMeta);
|
||||
await set(name, "meta:", pageMeta);
|
||||
}
|
||||
|
||||
@@ -88,14 +89,12 @@ export async function linkQueryProvider({
|
||||
query,
|
||||
pageName,
|
||||
}: QueryProviderEvent): Promise<any[]> {
|
||||
let uniqueLinks = new Set<string>();
|
||||
for (let { value: name } of await queryPrefix(`pl:${pageName}:`)) {
|
||||
uniqueLinks.add(name);
|
||||
let links: any[] = [];
|
||||
for (let { value: name, key } of await queryPrefix(`pl:${pageName}:`)) {
|
||||
const [, , pos] = key.split(":"); // Key: pl:page:pos
|
||||
links.push({ name, pos });
|
||||
}
|
||||
return applyQuery(
|
||||
query,
|
||||
[...uniqueLinks].map((l) => ({ name: l }))
|
||||
);
|
||||
return applyQuery(query, links);
|
||||
}
|
||||
|
||||
export async function deletePage() {
|
||||
|
||||
@@ -46,9 +46,12 @@ export async function instantiateTemplateCommand() {
|
||||
);
|
||||
|
||||
let parseTree = await parseMarkdown(text);
|
||||
let additionalPageMeta = extractMeta(parseTree, ["PAGENAME"]);
|
||||
let additionalPageMeta = extractMeta(parseTree, [
|
||||
"$name",
|
||||
"$disableDirectives",
|
||||
]);
|
||||
|
||||
let pageName = await prompt("Name of new page", additionalPageMeta.PAGENAME);
|
||||
let pageName = await prompt("Name of new page", additionalPageMeta.$name);
|
||||
if (!pageName) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,37 +18,4 @@ export async function queryComplete() {
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
prefix = await matchBefore('render "[^"]*');
|
||||
if (prefix) {
|
||||
let allPages = await listPages();
|
||||
return {
|
||||
from: prefix.from + 'render "'.length,
|
||||
options: allPages.map((pageMeta) => ({
|
||||
label: pageMeta.name,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
prefix = await matchBefore('#template "[^"]*');
|
||||
if (prefix) {
|
||||
let allPages = await listPages();
|
||||
return {
|
||||
from: prefix.from + '#template "'.length,
|
||||
options: allPages.map((pageMeta) => ({
|
||||
label: pageMeta.name,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
prefix = await matchBefore('#include "[^"]*');
|
||||
if (prefix) {
|
||||
let allPages = await listPages();
|
||||
return {
|
||||
from: prefix.from + '#include "'.length,
|
||||
options: allPages.map((pageMeta) => ({
|
||||
label: pageMeta.name,
|
||||
})),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,12 @@ test("Test parser", () => {
|
||||
],
|
||||
});
|
||||
|
||||
expect(parseQuery(`something render [[template/table]]`)).toStrictEqual({
|
||||
table: "something",
|
||||
filter: [],
|
||||
render: "template/table",
|
||||
});
|
||||
|
||||
expect(parseQuery(`something render "template/table"`)).toStrictEqual({
|
||||
table: "something",
|
||||
filter: [],
|
||||
|
||||
@@ -27,6 +27,9 @@ export function valueNodeToVal(valNode: ParseTree): any {
|
||||
case "String":
|
||||
let stringVal = valNode.children![0].text!;
|
||||
return stringVal.substring(1, stringVal.length - 1);
|
||||
case "PageRef":
|
||||
let pageRefVal = valNode.children![0].text!;
|
||||
return pageRefVal.substring(2, pageRefVal.length - 2);
|
||||
case "List":
|
||||
return collectNodesOfType(valNode, "Value").map((t) =>
|
||||
valueNodeToVal(t.children![0])
|
||||
|
||||
@@ -17,7 +17,8 @@ import { jsonToMDTable, queryRegex } from "./util";
|
||||
import { dispatch } from "@plugos/plugos-syscall/event";
|
||||
import { replaceAsync } from "../lib/util";
|
||||
import { parseMarkdown } from "@silverbulletmd/plugos-silverbullet-syscall/markdown";
|
||||
import { nodeAtPos } from "@silverbulletmd/common/tree";
|
||||
import { nodeAtPos, renderToText } from "@silverbulletmd/common/tree";
|
||||
import { extractMeta } from "./data";
|
||||
|
||||
export async function updateMaterializedQueriesCommand() {
|
||||
const currentPage = await getCurrentPage();
|
||||
@@ -34,7 +35,7 @@ export async function updateMaterializedQueriesCommand() {
|
||||
}
|
||||
|
||||
export const templateInstRegex =
|
||||
/(<!--\s*#(template|include)\s+"([^"]+)"(.+?)-->)(.+?)(<!--\s*\/\2\s*-->)/gs;
|
||||
/(<!--\s*#(inject|inject-clean|include)\s+\[\[([^\]]+)\]\](.*?)-->)(.+?)(<!--\s*\/\2\s*-->)/gs;
|
||||
|
||||
async function updateTemplateInstantiations(
|
||||
text: string,
|
||||
@@ -66,8 +67,11 @@ async function updateTemplateInstantiations(
|
||||
templateText = (await readPage(template)).text;
|
||||
}
|
||||
let newBody = templateText;
|
||||
// if it's a template (note a literal "include")
|
||||
if (type === "template") {
|
||||
// if it's a template injection (not a literal "include")
|
||||
if (type == "inject" || type === "inject-clean") {
|
||||
let tree = await parseMarkdown(templateText);
|
||||
extractMeta(tree, ["$disableDirectives"]);
|
||||
templateText = renderToText(tree);
|
||||
let templateFn = Handlebars.compile(
|
||||
replaceTemplateVars(templateText, pageName),
|
||||
{ noEscape: true }
|
||||
@@ -79,6 +83,29 @@ async function updateTemplateInstantiations(
|
||||
);
|
||||
}
|
||||
|
||||
async function cleanTemplateInstantiations(text: string): Promise<string> {
|
||||
return replaceAsync(
|
||||
text,
|
||||
templateInstRegex,
|
||||
async (fullMatch, startInst, type, template, args, body, endInst) => {
|
||||
if (type === "inject-clean") {
|
||||
body = body.replaceAll(
|
||||
queryRegex,
|
||||
(
|
||||
fullMatch: string,
|
||||
startQuery: string,
|
||||
query: string,
|
||||
body: string
|
||||
) => {
|
||||
return body.trim();
|
||||
}
|
||||
);
|
||||
}
|
||||
return `${startInst}${body}${endInst}`;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Called from client, running on server
|
||||
export async function updateMaterializedQueriesOnPage(
|
||||
pageName: string
|
||||
@@ -96,6 +123,12 @@ export async function updateMaterializedQueriesOnPage(
|
||||
}
|
||||
let newText = await updateTemplateInstantiations(text, pageName);
|
||||
let tree = await parseMarkdown(newText);
|
||||
let metaData = extractMeta(tree, ["$disableDirectives"]);
|
||||
if (metaData.$disableDirectives) {
|
||||
console.log("Directives disabled, skipping");
|
||||
return false;
|
||||
}
|
||||
newText = renderToText(tree);
|
||||
|
||||
newText = await replaceAsync(
|
||||
newText,
|
||||
@@ -106,7 +139,6 @@ export async function updateMaterializedQueriesOnPage(
|
||||
// If not a comment block, it's likely a code block, ignore
|
||||
return fullMatch;
|
||||
}
|
||||
// console.log("Text slice", newText.substring(index, index + 100));
|
||||
|
||||
let parsedQuery = parseQuery(replaceTemplateVars(query, pageName));
|
||||
|
||||
@@ -132,6 +164,7 @@ export async function updateMaterializedQueriesOnPage(
|
||||
}
|
||||
}
|
||||
);
|
||||
newText = await cleanTemplateInstantiations(newText);
|
||||
if (text !== newText) {
|
||||
await writePage(pageName, newText);
|
||||
return true;
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
import {LRParser} from "@lezer/lr"
|
||||
export const parser = LRParser.deserialize({
|
||||
version: 14,
|
||||
states: "&fOVQPOOOmQQO'#C^QOQPOOOtQPO'#C`OyQQO'#CkO!OQPO'#CmO!TQPO'#CnO!YQPO'#CoOOQO'#Cp'#CpO!_QQO,58xO!fQQO'#CcO#TQQO'#CaOOQO'#Ca'#CaOOQO,58z,58zO#lQPO,59VOOQO,59X,59XO#qQQO'#D`OOQO,59Y,59YOOQO,59Z,59ZOOQO-E6n-E6nO$YQQO,58}OtQPO,58|O$qQQO1G.qO%]QPO'#CrO%bQQO,59zOOQO'#Cg'#CgOOQO'#Ci'#CiO$YQQO'#CjOOQO'#Cd'#CdOOQO1G.i1G.iOOQO1G.h1G.hOOQO'#Cl'#ClOOQO7+$]7+$]OOQO,59^,59^OOQO-E6p-E6pO%yQPO'#C|O&RQPO,59UO$YQQO'#CqO&WQPO,59hOOQO1G.p1G.pOOQO,59],59]OOQO-E6o-E6o",
|
||||
stateData: "&`~OiOS~ORPO~OjRO|SO!QTO!RUO!TVO~OgQX~P[ORYO~O}^O~OX_O~OR`O~OYbO~OgQa~P[OkdOsdOtdOudOvdOwdOxdOydOzdO~O{eOgTXjTX|TX!QTX!RTX!TTX~ORfO~OqgOg!SXj!SX|!SX!Q!SX!R!SX!T!SX~OXlOYlO[lOliOmiOnjOokO~O!OoO!PoOg_ij_i|_i!Q_i!R_i!T_i~ORqO~OqgOg!Saj!Sa|!Sa!Q!Sa!R!Sa!T!Sa~OquOrpX~OrwO~OquOrpa~O",
|
||||
goto: "#d!TPP!UP!X!]!`!c!iPP!rP!r!r!X!w!X!X!X!z#Q#WPPPPPPPPP#^PPPPPPPPPPPPPPPPP#aRQOTWPXR]RR[RQZRRneQmdQskRxuVldkuRpfQXPRcXQvsRyvQh`RrhRtkRaU",
|
||||
nodeNames: "⚠ Program Query Name WhereClause LogicalExpr AndExpr FilterExpr Value Number String Bool Regex Null List OrderClause Order LimitClause SelectClause RenderClause",
|
||||
maxTerm: 51,
|
||||
states: "&fOVQPOOOmQQO'#C^QOQPOOOtQPO'#C`OyQQO'#CkO!OQPO'#CmO!TQPO'#CnO!YQPO'#CoOOQO'#Cq'#CqO!bQQO,58xO!iQQO'#CcO#WQQO'#CaOOQO'#Ca'#CaOOQO,58z,58zO#oQPO,59VOOQO,59X,59XO#tQQO'#DaOOQO,59Y,59YOOQO,59Z,59ZOOQO-E6o-E6oO$]QQO,58}OtQPO,58|O$tQQO1G.qO%`QPO'#CsO%eQQO,59{OOQO'#Cg'#CgOOQO'#Ci'#CiO$]QQO'#CjOOQO'#Cd'#CdOOQO1G.i1G.iOOQO1G.h1G.hOOQO'#Cl'#ClOOQO7+$]7+$]OOQO,59_,59_OOQO-E6q-E6qO%|QPO'#C}O&UQPO,59UO$]QQO'#CrO&ZQPO,59iOOQO1G.p1G.pOOQO,59^,59^OOQO-E6p-E6p",
|
||||
stateData: "&c~OjOS~ORPO~OkRO}SO!RTO!SUO!UVO~OhQX~P[ORYO~O!O^O~OX_O~OR`O~OYbOdbO~OhQa~P[OldOtdOudOvdOwdOxdOydOzdO{dO~O|eOhTXkTX}TX!RTX!STX!UTX~ORfO~OrgOh!TXk!TX}!TX!R!TX!S!TX!U!TX~OXlOYlO[lOmiOniOojOpkO~O!PoO!QoOh_ik_i}_i!R_i!S_i!U_i~ORqO~OrgOh!Tak!Ta}!Ta!R!Ta!S!Ta!U!Ta~OruOsqX~OswO~OruOsqa~O",
|
||||
goto: "#e!UPP!VP!Y!^!a!d!jPP!sP!s!s!Y!x!Y!Y!YP!{#R#XPPPPPPPPP#_PPPPPPPPPPPPPPPPP#bRQOTWPXR]RR[RQZRRneQmdQskRxuVldkuRpfQXPRcXQvsRyvQh`RrhRtkRaU",
|
||||
nodeNames: "⚠ Program Query Name WhereClause LogicalExpr AndExpr FilterExpr Value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QRP}!O%w!c!}%w#R#S%w#T#o%wR>QURP}!O%w!c!}%w#R#S%w#T#f%w#f#g>d#g#o%wR>iURP}!O%w!c!}%w#R#S%w#T#i%w#i#j>{#j#o%wR?QURP}!O%w!c!}%w#R#S%w#T#X%w#X#Y?d#Y#o%wR?kSmQRP}!O%w!c!}%w#R#S%w#T#o%wR?|URP}!O%w!c!}%w#R#S%w#T#[%w#[#]@`#]#o%wR@eURP}!O%w!c!}%w#R#S%w#T#X%w#X#Y@w#Y#o%wR@|URP}!O%w!c!}%w#R#S%w#T#f%w#f#gA`#g#o%wRAeURP}!O%w!c!}%w#R#S%w#T#X%w#X#YAw#Y#o%wRBOSkQRP}!O%w!c!}%w#R#S%w#T#o%w",
|
||||
tokenizers: [0, 1],
|
||||
topRules: {"Program":[0,1]},
|
||||
tokenPrec: 0
|
||||
|
||||
@@ -18,4 +18,5 @@ export const
|
||||
Order = 16,
|
||||
LimitClause = 17,
|
||||
SelectClause = 18,
|
||||
RenderClause = 19
|
||||
RenderClause = 19,
|
||||
PageRef = 20
|
||||
|
||||
@@ -84,7 +84,10 @@ export function parseQuery(query: string): ParsedQuery {
|
||||
|
||||
let renderNode = findNodeOfType(queryNode, "RenderClause");
|
||||
if (renderNode) {
|
||||
let renderNameNode = findNodeOfType(renderNode, "String");
|
||||
let renderNameNode = findNodeOfType(renderNode, "PageRef");
|
||||
if (!renderNameNode) {
|
||||
renderNameNode = findNodeOfType(renderNode, "String");
|
||||
}
|
||||
parsedQuery.render = valueNodeToVal(renderNameNode!);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ WhereClause { "where" LogicalExpr }
|
||||
OrderClause { "order" "by" Name Order? }
|
||||
LimitClause { "limit" Number }
|
||||
SelectClause { "select" commaSep<Name> }
|
||||
RenderClause { "render" String }
|
||||
RenderClause { "render" (PageRef | String) }
|
||||
|
||||
Order {
|
||||
"desc" | "asc"
|
||||
@@ -56,6 +56,9 @@ Null {
|
||||
String {
|
||||
("\"" | "“" | "”") ![\"”“]* ("\"" | "“" | "”")
|
||||
}
|
||||
PageRef {
|
||||
"[" "[" ![\]]* "]" "]"
|
||||
}
|
||||
Regex { "/" ( ![/\\\n\r] | "\\" _ )* "/"? }
|
||||
|
||||
Number { std.digit+ }
|
||||
|
||||
@@ -8,15 +8,9 @@ import {
|
||||
export const queryRegex =
|
||||
/(<!--\s*#query\s+(.+?)-->)(.+?)(<!--\s*\/query\s*-->)/gs;
|
||||
|
||||
export const queryStartRegex = /<!--\s*#query\s+(.+?)-->/s;
|
||||
export const directiveStartRegex = /<!--\s*#([\w\-]+)\s+(.+?)-->/s;
|
||||
|
||||
export const queryEndRegex = /<!--\s*\/query\s*-->/s;
|
||||
|
||||
// export function whiteOutQueries(text: string): string {
|
||||
// return text.replaceAll(queryRegex, (match) =>
|
||||
// new Array(match.length + 1).join(" ")
|
||||
// );
|
||||
// }
|
||||
export const directiveEndRegex = /<!--\s*\/([\w\-]+)\s*-->/s;
|
||||
|
||||
export function removeQueries(pt: ParseTree) {
|
||||
addParentPointers(pt);
|
||||
@@ -25,9 +19,11 @@ export function removeQueries(pt: ParseTree) {
|
||||
return false;
|
||||
}
|
||||
let text = t.children![0].text!;
|
||||
if (!queryStartRegex.exec(text)) {
|
||||
let match = directiveStartRegex.exec(text);
|
||||
if (!match) {
|
||||
return false;
|
||||
}
|
||||
let directiveType = match[1];
|
||||
let parentChildren = t.parent!.children!;
|
||||
let index = parentChildren.indexOf(t);
|
||||
let nodesToReplace: ParseTree[] = [];
|
||||
@@ -35,7 +31,8 @@ export function removeQueries(pt: ParseTree) {
|
||||
let n = parentChildren[i];
|
||||
if (n.type === "CommentBlock") {
|
||||
let text = n.children![0].text!;
|
||||
if (queryEndRegex.exec(text)) {
|
||||
let match = directiveEndRegex.exec(text);
|
||||
if (match && match[1] === directiveType) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user