ttcmd: adds hr element

help pages: adds a way to extract the table of contents to the parent,
smoothes out the rough loading on help pages
This commit is contained in:
2024-03-13 02:52:59 -06:00
parent 009e988a38
commit d0cb74bea8
12 changed files with 199 additions and 70 deletions

View File

@@ -63,8 +63,6 @@ TokenIdentifiers.set("card", {
return search(s, start, end, rx, crx);
},
parse(s) {
console.log(s);
const rx = /\[{2}\n+([\s\S]*)\n+\]{2}/;
const [_, content] = s.match(rx) || ["", "Unable to parse card"];
@@ -279,6 +277,20 @@ TokenIdentifiers.set("p", {
},
});
TokenIdentifiers.set("hr", {
rx: /^-{3,}$/gm,
parse(s) {
return {
content: s,
raw: s,
metadata: {},
type: "hr",
uuid: crypto.randomUUID(),
rendersContentOnly,
};
},
});
// const p = TokenIdentifiers.get("p");
// TokenIdentifiers.clear();
// p && TokenIdentifiers.set("p", p);

View File

@@ -3,22 +3,9 @@
import { zipArrays } from "../zip";
import { TokenIdentifiers } from "./TokenIdentifiers";
export const createElements = (body: string): [TokenMarker[], number] => {
const tabOptions = [
/^\s{2}(?!\s|\t)/m,
/^\s{4}(?!\s|\t)/m,
/^\t(?!\s|\t)]/m,
];
let tabSpacing = 0;
for (const [i, tabOption] of tabOptions.entries()) {
if (body.match(tabOption)) {
tabSpacing = i;
break;
}
}
export const createElements = (body: string): Token[] => {
const tokens = tokenize(body);
return [buildAbstractSyntaxTree(tokens), tabSpacing];
return buildAbstractSyntaxTree(tokens).map((t) => t.token);
};
const tokenize = (body: string) => {
@@ -159,7 +146,6 @@ const contentToChildren = (token: Token) => {
const splitMarker = "{{^^}}";
for (const child of token.children || []) {
if (token.type === "card" && child.type === "code") debugger;
content = content.replace(child.raw, splitMarker);
}