Opens an external site in a new window
Mental Health Awareness Month
“Community”
RODNEY LAB
  • Home
  • Plus +
  • Newsletter
  • Links
  • Profile
RODNEY LAB
  • Home
  • Plus +
  • Newsletter
  • Links

MDsveX rehype Plugins: Pimp your Blog Posts # MDsveX rehype Plugins: Pimp your Blog Posts #

blurry low resolution placeholder image MDsveX rehype Plugins
  1. Home Rodney Lab Home
  2. Blog Posts Rodney Lab Blog Posts
  3. SvelteKit SvelteKit Blog Posts
<PREVIOUS POST
NEXT POST >
LATEST POST >>

MDsveX rehype Plugins: Pimp your Blog Posts #

Published: 4 years ago
3 minute read
Gunning Fog Index: 6
3 comments
Content by Rodney
blurry low resolution placeholder image Author Image: Rodney from Rodney Lab
SHARE:

🔌 MDsveX rehype Plugins: Introduction #

MDsveX rehype plugins offer an easy way to add some polish to your Markdown based content. They work by inserting themselves into the generation process of your site's HTML from Markdown. We focus on rehype plugins in this video, though remark plugins also offer fantastic functionality, doing their magic slightly earlier in the generation process. We will see how it takes less than five minutes to add automatically generated tables of contents to your blog posts. What's more, it's nothing more complicated than installing a couple of plugins and adding them to an array in our config. Although we just look at tables of contents (TOC) here, you can also use rehype plugins to make your emoji accessible , sanitize HTML  or add syntax highlighting . You can apply what we see in this video to any of those applications and more. Have a look at the video and throw your questions into a comment below.

📹 MDsveX rehype Plugins: Video #

Please enable JavaScript to watch the video 📼

MDsveX rehype Plugins

🖥 Code #

Installing the Plugins #

    
pnpm add -D @jsdevtools/rehype-toc rehype-slug # or use npm instead of pnpm
Install the rehype plugins used in the video.

Updating the SvelteKit Configuration #

svelte.config.js
svelte
    
1 /** @type {import('@sveltejs/kit').Config} */
2 import adapter from '@sveltejs/adapter-netlify';
3 import { mdsvex } from 'mdsvex';
4 import preprocess from 'svelte-preprocess';
5 import toc from '@jsdevtools/rehype-toc';
6 import rehypeSlug from 'rehype-slug';
7
8 const config = {
9 extensions: ['.svelte', '.md', '.svelte.md'],
10 preprocess: [
11 mdsvex({ extensions: ['.svelte.md', '.md', '.svx'], rehypePlugins: [rehypeSlug, toc] }),
12 preprocess({
13 scss: {
14 prependData: "@import 'src/lib/styles/variables.scss';",
15 },
16 }),
17 ],
18 // TRUNCATED...
19 };
Configure mdsvex to use the rehype plugins.

Some Styling #

src/lib/styles/styles.scss
svelte
    
172 h1 > a {
173 color: inherit;
174 text-decoration: none;
175 }
176 h2 > a,
177 h3 > a,
178 h4 > a,
179 h5 > a,
180 h6 > a {
181 text-decoration: none;
182 color: inherit;
183 }
184
185 .toc {
186 .toc-level-1 {
187 font-size: $font-size-3;
188 font-weight: $font-weight-bold;
189 }
190 }
Add some basic styling to the table of contents.

🗳 Poll #

How familiar are you with rehype and remark plugins?
Voting reveals latest results.

🔗 Links #

  • MDsveX Blog Starter on Rodney Lab GitHub
  • mdsvex plugin docs on rehype 
  • List of rehype plugins  
  • rehype-toc plugin docs 
  • rehype-slug plugin docs 
  • Complete Code for Final Product 
  • Twitter handle: @askRodney 

🙏🏽 MDsveX rehype Plugins: Feedback #

If you have found this video useful, see links below for related content on this site. I do hope you learned one new thing from the video. Let me know if there are any ways I can improve on it. I hope you will use the code or starter in your own projects. Be sure to share your work on Twitter, giving me a mention, so I can see what you did. Finally, be sure to let me know ideas for other short videos you would like to see. Read on to find ways to get in touch, further below. If you have found this post useful, even though you can only afford even a tiny contribution, please consider supporting me through Buy me a Coffee.

Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on Twitter and also askRodney on Telegram . Also, see further ways to get in touch with Rodney Lab. I post regularly on SvelteKit as well as Search Engine Optimization among other topics. Also, subscribe to the newsletter to keep up-to-date with our latest projects.

Thanks for reading this post. I hope you found it valuable. Please get in touch with your feedback and suggestions for posts you would like to see. Read more about me …

blurry low resolution placeholder image Rodney from Rodney Lab
TAGS:
SVELTEKIT

Reposts:

Reposts

  • Tan Li Hau 🤔 profile avatar
  • Svelte Society 🧡 profile avatar

Likes:

Likes

  • The Link Geeks profile avatar
  • Horace Keung profile avatar
  • Bill Tihen profile avatar
  • Achilles Moraites profile avatar
  • delemercier profile avatar
  • Zen profile avatar
  • Svelte Society 🧡 profile avatar
Reposts & likes provided by Mastodon & X via Webmentions.

Related Posts

blurry low resolution placeholder image Get Started with SvelteKit Headless WordPress

Get Started with SvelteKit Headless WordPress

plus
sveltekit
<PREVIOUS POST
NEXT POST >
LATEST POST >>

Leave a comment …

Your information will be handled in line with our Privacy Policy .

Comments

  • Tristen Grant

    Have you played around with svelte-image in Sveltkit? I'm trying to get my images to be responsive and optimized.

    4 years ago
    • Rodney

      Hi Tristen, good question! I haven't had a chance yet, been using Imgix, but SvelteKit images is on my list. I heard you can use the ElderJS image plugin in SvelteKit https://www.npmjs.com/package/@elderjs/plugin-images that might be worth a try.
      4 years ago
    • Rodney

      Hi Tristen, sorry for the delay. I have just written a new post on how to create responsive optimised images in SvelteKit with placeholders to reduce Cumulative Layout Shift. Hope that is helpful for you.
      4 years ago

Ask for more

1 Nov 2022 — Astro Server-Side Rendering: Edge Search Site
3 Oct 2022 — Svelte eCommerce Site: SvelteKit Snipcart Storefront
1 Sept 2022 — Get Started with SvelteKit Headless WordPress

Copyright © 2020 – 2025 Rodney Johnson. All Rights Reserved. Please read important copyright and intellectual property information.

  • Home
  • Profile
  • Plus +
  • Newsletter
  • Contact
  • Links
  • Terms of Use
  • Privacy Policy
We use cookies  to enhance visitors’ experience. Please click the “Options” button to make your choice.  Learn more here.