Add ability to convert #use and #import via a command
This commit is contained in:
parent
6892756397
commit
ae17385dd9
@ -209,7 +209,7 @@ export async function updateDirectives(
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function convertToLiveQuery() {
|
export async function convertToLive() {
|
||||||
const text = await editor.getText();
|
const text = await editor.getText();
|
||||||
const pos = await editor.getCursor();
|
const pos = await editor.getCursor();
|
||||||
const tree = await markdown.parseMarkdown(text);
|
const tree = await markdown.parseMarkdown(text);
|
||||||
@ -226,7 +226,11 @@ export async function convertToLiveQuery() {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const queryText = renderToText(directive!.children![0].children![1]);
|
console.log("Got this directive", directive);
|
||||||
|
const startNode = directive.children![0];
|
||||||
|
const startNodeText = renderToText(startNode);
|
||||||
|
if (startNodeText.includes("#query")) {
|
||||||
|
const queryText = renderToText(startNode.children![1]);
|
||||||
await editor.dispatch({
|
await editor.dispatch({
|
||||||
changes: {
|
changes: {
|
||||||
from: directive.from,
|
from: directive.from,
|
||||||
@ -234,4 +238,25 @@ export async function convertToLiveQuery() {
|
|||||||
insert: "```query\n" + queryText + "\n```",
|
insert: "```query\n" + queryText + "\n```",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} else if (
|
||||||
|
startNodeText.includes("#use") || startNodeText.includes("#include")
|
||||||
|
) {
|
||||||
|
const pageRefMatch = /\[\[([^\]]+)\]\]\s*([^\-]+)?/.exec(startNodeText);
|
||||||
|
if (!pageRefMatch) {
|
||||||
|
await editor.flashNotification(
|
||||||
|
"No page reference found in directive",
|
||||||
|
"error",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const val = pageRefMatch[2];
|
||||||
|
await editor.dispatch({
|
||||||
|
changes: {
|
||||||
|
from: directive.from,
|
||||||
|
to: directive.to,
|
||||||
|
insert: '```template\npage: "[[' + pageRefMatch[1] + ']]"\n' +
|
||||||
|
(val ? `val: ${val}\n` : "") + "```",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,6 @@ functions:
|
|||||||
|
|
||||||
# Conversion
|
# Conversion
|
||||||
convertToLiveQuery:
|
convertToLiveQuery:
|
||||||
path: command.ts:convertToLiveQuery
|
path: command.ts:convertToLive
|
||||||
command:
|
command:
|
||||||
name: "Directive: Convert Query to Live Query"
|
name: "Directive: Convert to Live Query/Template"
|
||||||
|
Loading…
Reference in New Issue
Block a user