ttcMD: fixes typedef file needing to be imported
This commit is contained in:
@@ -1,9 +1,3 @@
|
||||
import {
|
||||
IdentifiedToken,
|
||||
Token,
|
||||
TokenAttributes,
|
||||
TokenRenderer,
|
||||
} from "@/types";
|
||||
import { sanitize } from "isomorphic-dompurify";
|
||||
import Link from "next/link";
|
||||
import { Fragment } from "react";
|
||||
@@ -114,6 +108,8 @@ export const buildOnlyDefaultElements = () => {
|
||||
);
|
||||
});
|
||||
|
||||
const usedIds: string[] = [];
|
||||
|
||||
const rendersContentOnly = true;
|
||||
const rendersChildrenOnly = true;
|
||||
|
||||
@@ -292,12 +288,14 @@ export const buildOnlyDefaultElements = () => {
|
||||
|
||||
// heading
|
||||
registerIdentifier("heading", /^#+\s(.*?)$/gm, (s, rx) => {
|
||||
const content = s.match(new RegExp(rx, ""))?.at(1) ||
|
||||
"Unable to parse heading";
|
||||
return {
|
||||
content: s.match(new RegExp(rx, ""))?.at(1) ||
|
||||
"Unable to parse heading",
|
||||
content: content,
|
||||
raw: s,
|
||||
metadata: {
|
||||
strength: s.match(/#/g)?.length.toString() || "1",
|
||||
id: generateId(content, usedIds),
|
||||
},
|
||||
uuid: crypto.randomUUID(),
|
||||
rendersContentOnly,
|
||||
@@ -698,3 +696,18 @@ function search(
|
||||
lastIndex: oldEnd === end ? end : start + s.match(openRx)![0].length,
|
||||
};
|
||||
}
|
||||
|
||||
// Finds a unique id for things like headings
|
||||
function generateId(t: string, usedIds: string[]) {
|
||||
let id = t.toLowerCase().replace(/[^a-z\s]/ig, "").trim().replaceAll(
|
||||
" ",
|
||||
"-",
|
||||
);
|
||||
let idNum = 1;
|
||||
while (usedIds.includes(id)) {
|
||||
id = id.replace(/-[0-9]+$/g, "");
|
||||
id += "-" + idNum;
|
||||
idNum++;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { FrontMatter, Token, TokenMarker } from "@/types";
|
||||
import { zipArrays } from "../zip";
|
||||
import { buildOnlyDefaultElements, TokenRenderers } from "./TokenIdentifiers";
|
||||
|
||||
|
Reference in New Issue
Block a user