md-macros
1 min read • 151 words
Markdown is great for its simplicity and easy-to-read syntax. Sometimes you want to embed rich markup or components inside of a markdown document. How do you do this without writing ugly html along side your content?
Enter md-macros, an npm package that I created and use myself on this blog. It allows me to link from one post to another with \\[[macro:postLink slug="welcome-2"]]
(update 2023-12: I now support wiki-style backlinks popularized by second brain apps like Obsidian), or embed a youtube video with \\[[macro:youtubeEmbed url="<youtube video url>"]]
. This enables me to keep my markdown documents clean and free of html.
Each macro maps to a simple JavaScript function, making this a highly extensible library. I use it in other projects to embed a table of contents inside of the README.
Check out the code on my github, or use it in one of your projects by installing the npm package.