Awesome frontmatter (#617)

Live Frontmatter Templates
This commit is contained in:
Zef Hemel
2024-01-04 20:08:12 +01:00
committed by GitHub
parent 9040993232
commit 91027af5fe
53 changed files with 646 additions and 342 deletions
+35
View File
@@ -135,6 +135,38 @@ const CommandLink: MarkdownConfig = {
],
};
export const templateDirectiveRegex = /^\{\{([^\}]+)\}\}/;
const TemplateDirective: MarkdownConfig = {
defineNodes: [
{ name: "TemplateDirective", style: t.monospace },
{ name: "TemplateDirectiveMark", style: t.monospace },
],
parseInline: [
{
name: "TemplateDirective",
parse(cx, next, pos) {
let match: RegExpMatchArray | null;
if (
next != 123 /* '{' */ ||
!(match = templateDirectiveRegex.exec(cx.slice(pos, cx.end)))
) {
return -1;
}
const fullMatch = match[0];
const endPos = pos + fullMatch.length;
return cx.addElement(
cx.elt("TemplateDirective", pos, endPos, [
cx.elt("TemplateDirectiveMark", pos, pos + 2),
cx.elt("TemplateDirectiveMark", endPos - 2, endPos),
]),
);
},
after: "Emphasis",
},
],
};
const HighlightDelim = { resolve: "Highlight", mark: "HighlightMark" };
export const Highlight: MarkdownConfig = {
@@ -175,6 +207,8 @@ export const highlightingQueryParser = queryParser.configure({
],
});
export { parser as expressionParser } from "./parse-expression.js";
export const attributeStartRegex = /^\[([\w\$]+)(::?\s*)/;
export const Attribute: MarkdownConfig = {
@@ -355,6 +389,7 @@ export default function buildMarkdown(mdExtensions: MDExt[]): Language {
TaskList,
Comment,
Highlight,
TemplateDirective,
Strikethrough,
Table,
...mdExtensions.map(mdExtensionSyntaxConfig),