diff options
Diffstat (limited to 'examples/with-markdown-plugins')
-rw-r--r-- | examples/with-markdown-plugins/add-classes.mjs | 16 | ||||
-rw-r--r-- | examples/with-markdown-plugins/astro.config.mjs | 2 | ||||
-rw-r--r-- | examples/with-markdown-plugins/package.json | 2 |
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", |