[Archived] Archived WIP of vielle.dev

Add flags to blockquotes

vielle.dev 58731484 1c339163

verified
+31 -7
+1 -1
astro.config.mjs
··· 15 15 site: "https://vielle.dev", 16 16 17 17 markdown: { 18 - // remarkPlugins: [[remarkToc, { heading: "toc", maxDepth: 3 }]], 18 + remarkPlugins: [[remarkToc, { heading: "toc", maxDepth: 3 }]], 19 19 // @ts-expect-error idk why this gets flagged as wrong 20 20 rehypePlugins: [rehypeAccessibleEmojis, rehypeCustomHtml], 21 21 },
+30 -6
rehype-custom-html.ts
··· 1 1 import type { Plugin } from "unified"; 2 - import type { Root } from "hast"; 2 + import type { Root, Element } from "hast"; 3 3 type Options = {}; 4 4 5 + function blockquote(node: Element) { 6 + for (const child of node.children) { 7 + if (child.type === "element" && child.children[0].type === "text") { 8 + const flag = child.children[0].value.match(/(?<=^\$).*/gm); 9 + if (flag?.length !== 1) continue; 10 + 11 + if (!node.properties.style) 12 + node.properties.style = "flag-" + flag[0].toLowerCase(); 13 + else if (node.properties.styles instanceof Array) 14 + node.properties.styles.push("flag-" + flag[0].toLowerCase()); 15 + else if (typeof node.properties.styles === "string") 16 + node.properties.styles + "flag-" + flag[0].toLowerCase(); 17 + else 18 + throw new Error( 19 + `${node.position?.start.line}:${node.position?.start.column} [style] malformed!! (${node.properties.style})`, 20 + ); 21 + } 22 + } 23 + } 24 + 5 25 const plugin: Plugin<[Options], Root> = function (options) { 6 - return function (node, file) { 7 - if (file.basename !== "full-test.md") return; 8 - console.log(node); 9 - for (const n of node.children) { 10 - console.log(n.type == "element" ? n.tagName : n.type); 26 + return function (root, _) { 27 + for (const node of root.children) { 28 + if (node.type === "element") 29 + switch (node.tagName) { 30 + case "blockquote": { 31 + blockquote(node); 32 + break; 33 + } 34 + } 11 35 } 12 36 }; 13 37 };