summaryrefslogtreecommitdiff
path: root/examples/with-markdown-plugins
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@matthewphillips.info> 2022-01-04 15:09:10 -0500
committerGravatar GitHub <noreply@github.com> 2022-01-04 15:09:10 -0500
commit27705888678a662c9222e7baa555448f5fc259ed (patch)
tree0bc5c97aa43f2ff87743cdef38d89b8b16db5125 /examples/with-markdown-plugins
parenteae959f1a7265f5fe7d220613353b4ae0ac97ffe (diff)
downloadastro-27705888678a662c9222e7baa555448f5fc259ed.tar.gz
astro-27705888678a662c9222e7baa555448f5fc259ed.tar.zst
astro-27705888678a662c9222e7baa555448f5fc259ed.zip
Remove rehype-add-classes (#2309)
* Remove rehype-add-classes * Fix the markdown plugin test
Diffstat (limited to 'examples/with-markdown-plugins')
-rw-r--r--examples/with-markdown-plugins/add-classes.mjs16
-rw-r--r--examples/with-markdown-plugins/astro.config.mjs2
-rw-r--r--examples/with-markdown-plugins/package.json2
3 files changed, 18 insertions, 2 deletions
diff --git a/examples/with-markdown-plugins/add-classes.mjs b/examples/with-markdown-plugins/add-classes.mjs
new file mode 100644
index 000000000..54879e55d
--- /dev/null
+++ b/examples/with-markdown-plugins/add-classes.mjs
@@ -0,0 +1,16 @@
+import { selectAll } from 'hast-util-select';
+
+export default additions => {
+ const adders = Object.entries(additions).map(adder);
+ return node => adders.forEach(a => a(node));
+};
+
+const adder = ([selector, className]) => {
+ const writer = write(className);
+ return node => selectAll(selector, node).forEach(writer);
+};
+
+const write = className => ({ properties }) => {
+ if(!properties.className) properties.className = className;
+ else properties.className += ` ${className}`;
+};
diff --git a/examples/with-markdown-plugins/astro.config.mjs b/examples/with-markdown-plugins/astro.config.mjs
index eb7011933..0fbb40de6 100644
--- a/examples/with-markdown-plugins/astro.config.mjs
+++ b/examples/with-markdown-plugins/astro.config.mjs
@@ -18,7 +18,7 @@ export default /** @type {import('astro').AstroUserConfig} */ ({
rehypePlugins: [
['rehype-autolink-headings', { behavior: 'prepend' }],
['rehype-toc', { headings: ['h2', 'h3'] }],
- ['rehype-add-classes', { 'h1,h2,h3': 'title' }],
+ [new URL('./add-classes.mjs', import.meta.url).pathname, { 'h1,h2,h3': 'title' }],
'rehype-slug',
],
},
diff --git a/examples/with-markdown-plugins/package.json b/examples/with-markdown-plugins/package.json
index 6ad7c316d..ab779217b 100644
--- a/examples/with-markdown-plugins/package.json
+++ b/examples/with-markdown-plugins/package.json
@@ -10,7 +10,7 @@
},
"devDependencies": {
"astro": "^0.22.5",
- "rehype-add-classes": "^1.0.0",
+ "hast-util-select": "5.0.1",
"rehype-autolink-headings": "^6.1.0",
"rehype-slug": "^5.0.0",
"rehype-toc": "^3.0.2",