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 styles to <blockquote>
vielle.dev
9 months ago
073c8027
58731484
verified
This commit was signed with the committer's
known signature
.
vielle.dev
SSH Key Fingerprint:
SHA256:/4bvxqoEh9iMdjAPgcgAgXKZZQTROL3ULiPt6nH9RSs=
+47
-9
3 changed files
expand all
collapse all
unified
split
posts
full-test.md
rehype-custom-html.ts
src
pages
blog
[id].astro
+1
-1
posts/full-test.md
···
41
41
42
42
## Blockquotes
43
43
44
44
-
> and this, a block quote
44
44
+
> and this, a block quote
45
45
> which is multiline
46
46
47
47
> and heres another
+15
-8
rehype-custom-html.ts
···
1
1
import type { Plugin } from "unified";
2
2
-
import type { Root, Element } from "hast";
2
2
+
import type { Root, Element, Node } from "hast";
3
3
type Options = {};
4
4
5
5
function blockquote(node: Element) {
···
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
+
child.children.shift();
11
11
+
// finiky to get types working bc shift mutation etc
12
12
+
if (
13
13
+
(child.children[0] as Node).type === "element" &&
14
14
+
(child.children[0] as Node as Element).tagName === "br"
15
15
+
)
16
16
+
child.children.shift();
10
17
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();
18
18
+
if (!node.properties.class)
19
19
+
node.properties.class = ["flag-" + flag[0].toLowerCase()];
20
20
+
else if (node.properties.class instanceof Array)
21
21
+
node.properties.class.push("flag-" + flag[0].toLowerCase());
22
22
+
else if (typeof node.properties.class === "string")
23
23
+
node.properties.class + "flag-" + flag[0].toLowerCase();
17
24
else
18
25
throw new Error(
19
19
-
`${node.position?.start.line}:${node.position?.start.column} [style] malformed!! (${node.properties.style})`,
26
26
+
`${node.position?.start.line}:${node.position?.start.column} [class] malformed!! (${node.properties.class})`,
20
27
);
21
28
}
22
29
}
+31
src/pages/blog/[id].astro
···
87
87
});
88
88
</script>
89
89
90
90
+
<!-- post content styles -->
91
91
+
<style is:global>
92
92
+
blockquote {
93
93
+
--accent: #a8a8a8;
94
94
+
border-left: 0.2rem solid var(--accent);
95
95
+
padding: 1rem 4rem 1rem 1rem;
96
96
+
margin: 1rem;
97
97
+
border-radius: 0.5rem;
98
98
+
background-color: rgb(from var(--accent) r g b / 0.5);
99
99
+
width: fit-content;
100
100
+
min-width: 20rem;
101
101
+
102
102
+
&::before {
103
103
+
content: var(--icon) " " var(--name);
104
104
+
}
105
105
+
}
106
106
+
107
107
+
blockquote.flag-note {
108
108
+
--accent: skyblue;
109
109
+
--icon: "📝";
110
110
+
--name: "Note";
111
111
+
}
112
112
+
113
113
+
blockquote.flag-alert {
114
114
+
--accent: orangered;
115
115
+
--icon: "🚨";
116
116
+
--name: "Alert";
117
117
+
}
118
118
+
</style>
119
119
+
120
120
+
<!-- page styles -->
90
121
<style>
91
122
@property --bg {
92
123
syntax: "<color>";