tcmd: token uuids, fixes a few issues with poppables
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { zipArrays } from "../zip";
|
||||
import { singleLineTokens, tokenizeLine } from "./tokenizeLine";
|
||||
import { tokenizeLine } from "./tokenizeLine";
|
||||
import { tokenizeBlock } from "./tokenizeBlock";
|
||||
import { tokenizeInline } from "./tokenizeInline";
|
||||
import { tokenizeParagraph } from "./tokenizeParagraph";
|
||||
|
||||
export const createElements = (body: string) => {
|
||||
@@ -43,6 +42,7 @@ const tokenize = (body: string) => {
|
||||
closed: false,
|
||||
metadata: {},
|
||||
type: "block",
|
||||
uuid: crypto.randomUUID(),
|
||||
};
|
||||
blockTokens.push(openBT);
|
||||
}
|
||||
@@ -66,6 +66,7 @@ const tokenize = (body: string) => {
|
||||
line: paragraph,
|
||||
raw: paragraph,
|
||||
type: "text",
|
||||
uuid: crypto.randomUUID(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -78,6 +79,7 @@ const tokenize = (body: string) => {
|
||||
content: [],
|
||||
metadata: {},
|
||||
type: "p",
|
||||
uuid: crypto.randomUUID(),
|
||||
};
|
||||
openBT.children.push(openP);
|
||||
paragraphTokens.push(openP);
|
||||
|
@@ -26,6 +26,7 @@ const blockTokens: {
|
||||
},
|
||||
children: [],
|
||||
closed: false,
|
||||
uuid: crypto.randomUUID(),
|
||||
};
|
||||
},
|
||||
},
|
||||
@@ -38,6 +39,7 @@ const blockTokens: {
|
||||
metadata: {},
|
||||
children: [],
|
||||
closed: false,
|
||||
uuid: crypto.randomUUID(),
|
||||
};
|
||||
},
|
||||
},
|
||||
@@ -51,6 +53,7 @@ const blockTokens: {
|
||||
metadata: { title },
|
||||
children: [],
|
||||
closed: false,
|
||||
uuid: crypto.randomUUID(),
|
||||
};
|
||||
},
|
||||
},
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { zipArrays } from "../zip";
|
||||
|
||||
export const tokenizeInline = (line: string, recursive?: boolean) => {
|
||||
if (recursive) console.log("recursive call");
|
||||
export const tokenizeInline = (line: string) => {
|
||||
line = line.trim();
|
||||
const originalLine = line;
|
||||
const insertMarker = "\u{03A9}";
|
||||
@@ -43,6 +42,7 @@ export const tokenizeInline = (line: string, recursive?: boolean) => {
|
||||
line.split(new RegExp(insertMarker + "{2,}")).map((t): InlineToken => ({
|
||||
content: t,
|
||||
type: "text",
|
||||
uuid: crypto.randomUUID(),
|
||||
})),
|
||||
tokens,
|
||||
).filter((t) => t.content);
|
||||
@@ -69,6 +69,7 @@ export const inlineTokens: {
|
||||
type: "bold",
|
||||
end,
|
||||
start,
|
||||
uuid: crypto.randomUUID(),
|
||||
});
|
||||
},
|
||||
replace(l) {
|
||||
@@ -87,6 +88,7 @@ export const inlineTokens: {
|
||||
},
|
||||
start,
|
||||
end,
|
||||
uuid: crypto.randomUUID(),
|
||||
});
|
||||
},
|
||||
replace(l) {
|
||||
@@ -106,6 +108,7 @@ export const inlineTokens: {
|
||||
data: {
|
||||
src,
|
||||
},
|
||||
uuid: crypto.randomUUID(),
|
||||
});
|
||||
},
|
||||
replace(l) {
|
||||
@@ -116,7 +119,6 @@ export const inlineTokens: {
|
||||
rx: /\^\[(.*?)\]<<(.*?)>>/gm,
|
||||
create(content, start, end, tokens) {
|
||||
const [_, text, popover] = content;
|
||||
// tokenizeInline("", true);
|
||||
tokens.push({
|
||||
content: text,
|
||||
end,
|
||||
@@ -125,6 +127,7 @@ export const inlineTokens: {
|
||||
data: {
|
||||
popover: tokenizeInline(popover),
|
||||
},
|
||||
uuid: crypto.randomUUID(),
|
||||
});
|
||||
},
|
||||
replace(l) {
|
||||
|
@@ -26,6 +26,7 @@ export const tokenizeLine = (
|
||||
line: tokenizeInline(line),
|
||||
type: "text",
|
||||
raw: line,
|
||||
uuid: crypto.randomUUID(),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -33,28 +34,53 @@ export const singleLineTokens: SingleLineCfg[] = [
|
||||
{
|
||||
rx: /^#\s/,
|
||||
create(line) {
|
||||
return ({ type: "h1", line, raw: line, cfg: this });
|
||||
return ({
|
||||
type: "h1",
|
||||
line,
|
||||
raw: line,
|
||||
cfg: this,
|
||||
uuid: crypto.randomUUID(),
|
||||
});
|
||||
},
|
||||
replaceRx: /^#\s/,
|
||||
},
|
||||
{
|
||||
rx: /^##\s/,
|
||||
create(line) {
|
||||
return ({ type: "h2", line, raw: line, cfg: this });
|
||||
return ({
|
||||
type: "h2",
|
||||
line,
|
||||
raw: line,
|
||||
cfg: this,
|
||||
uuid: crypto.randomUUID(),
|
||||
});
|
||||
},
|
||||
replaceRx: /^##\s/,
|
||||
},
|
||||
{
|
||||
rx: /^###\s/,
|
||||
create(line) {
|
||||
return ({ type: "h3", line, raw: line, cfg: this });
|
||||
return ({
|
||||
type: "h3",
|
||||
line,
|
||||
raw: line,
|
||||
cfg: this,
|
||||
uuid: crypto.randomUUID(),
|
||||
});
|
||||
},
|
||||
replaceRx: /^###\s/,
|
||||
},
|
||||
{
|
||||
rx: /^-\s/,
|
||||
create(line) {
|
||||
return ({ type: "list1", line, raw: line, mends: true, cfg: this });
|
||||
return ({
|
||||
type: "list1",
|
||||
line,
|
||||
raw: line,
|
||||
mends: true,
|
||||
cfg: this,
|
||||
uuid: crypto.randomUUID(),
|
||||
});
|
||||
},
|
||||
replaceRx: /^-\s/,
|
||||
shouldMendNextLine: true,
|
||||
@@ -62,7 +88,14 @@ export const singleLineTokens: SingleLineCfg[] = [
|
||||
{
|
||||
rx: /^[\t\s]{2}-\s/,
|
||||
create(line) {
|
||||
return ({ type: "list2", line, raw: line, mends: true, cfg: this });
|
||||
return ({
|
||||
type: "list2",
|
||||
line,
|
||||
raw: line,
|
||||
mends: true,
|
||||
cfg: this,
|
||||
uuid: crypto.randomUUID(),
|
||||
});
|
||||
},
|
||||
replaceRx: /^[\t\s]{2}-\s/,
|
||||
shouldMendNextLine: true,
|
||||
|
@@ -34,8 +34,10 @@ const blockTokens: {
|
||||
line: line.replace(/```.*?\n/g, "").replace(/\n```/, ""),
|
||||
type: "text",
|
||||
raw: line,
|
||||
uuid: crypto.randomUUID(),
|
||||
}],
|
||||
allowsInline: false,
|
||||
uuid: crypto.randomUUID(),
|
||||
};
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user