tangled
alpha
login
or
join now
vielle.dev
/
site-archive
0
fork
atom
[Archived] Archived WIP of vielle.dev
0
fork
atom
overview
issues
pulls
pipelines
Add flags to blockquotes
vielle.dev
9 months ago
58731484
1c339163
verified
This commit was signed with the committer's
known signature
.
vielle.dev
SSH Key Fingerprint:
SHA256:/4bvxqoEh9iMdjAPgcgAgXKZZQTROL3ULiPt6nH9RSs=
+31
-7
2 changed files
expand all
collapse all
unified
split
astro.config.mjs
rehype-custom-html.ts
+1
-1
astro.config.mjs
···
15
15
site: "https://vielle.dev",
16
16
17
17
markdown: {
18
18
-
// remarkPlugins: [[remarkToc, { heading: "toc", maxDepth: 3 }]],
18
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
2
-
import type { Root } from "hast";
2
2
+
import type { Root, Element } from "hast";
3
3
type Options = {};
4
4
5
5
+
function blockquote(node: Element) {
6
6
+
for (const child of node.children) {
7
7
+
if (child.type === "element" && child.children[0].type === "text") {
8
8
+
const flag = child.children[0].value.match(/(?<=^\$).*/gm);
9
9
+
if (flag?.length !== 1) continue;
10
10
+
11
11
+
if (!node.properties.style)
12
12
+
node.properties.style = "flag-" + flag[0].toLowerCase();
13
13
+
else if (node.properties.styles instanceof Array)
14
14
+
node.properties.styles.push("flag-" + flag[0].toLowerCase());
15
15
+
else if (typeof node.properties.styles === "string")
16
16
+
node.properties.styles + "flag-" + flag[0].toLowerCase();
17
17
+
else
18
18
+
throw new Error(
19
19
+
`${node.position?.start.line}:${node.position?.start.column} [style] malformed!! (${node.properties.style})`,
20
20
+
);
21
21
+
}
22
22
+
}
23
23
+
}
24
24
+
5
25
const plugin: Plugin<[Options], Root> = function (options) {
6
6
-
return function (node, file) {
7
7
-
if (file.basename !== "full-test.md") return;
8
8
-
console.log(node);
9
9
-
for (const n of node.children) {
10
10
-
console.log(n.type == "element" ? n.tagName : n.type);
26
26
+
return function (root, _) {
27
27
+
for (const node of root.children) {
28
28
+
if (node.type === "element")
29
29
+
switch (node.tagName) {
30
30
+
case "blockquote": {
31
31
+
blockquote(node);
32
32
+
break;
33
33
+
}
34
34
+
}
11
35
}
12
36
};
13
37
};