npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

markdown-macros

v0.0.1

Published

Execute macros in Markdown content. Support for remark, markdown-it and marked.

Readme

markdown-macros

author herve-perchec release pipeline-status coverage package downloads issues license

Table of contents

🍵 Introduction

This library was designed to run macros within Markdown content, but it can be used for any other text-based content. It relies on a specific syntax (@MACRO:) that you can use to execute your own logic, perform text replacements, generate Markdown content, and more.

It provides a comprehensive and fully typed API with TypeScript, as well as plugins for remark, markdown-it, and marked.

⚠ Note that when using these plugins, the library will act as a preprocessor!

🚀 Get started

This package is published on NPM.

npm install markdown-macros

🛠️ Usage

In the following examples, we will use the buildMacros, parse and execMacros functions.

Say we have this markdown content:

# My document

Say "@MACRO:HELLO()" in a paragraph!

Learn more about [Darth Vader](@MACRO:WIKI_URL('Darth_Vader')).

First, we have to define our macros. A macro definition is an object with a exec function that takes any JSON compatible arguments.

Note that macro names will be normalized (transformed to CONSTANT_CASE). See isValidMacroName function.

Also, note that if you pass unknown identifiers to a macro expression, it will throw a parsing error:

// @MACRO:EXAMPLE('foo', { "bar": baz })
// ❌ Unable to parse Identifier: "baz"
const macroDefinitions = {
  hello: {
    exec: () => 'Hello!'
  },
  wikiUrl: {
    exec: (value: string) => `https://en.wikipedia.org/wiki/${value}`
  }
}

Then, use the buildMacros and execMacros to perform replacements:

import { buildMacros, execMacros } from 'markdown-macros'

const macros = buildMacros(macroDefinitions)

const result = execMacros(macros, content)

console.log(result)

The result will be:

# My document

Say "Hello!" in a paragraph!

Learn more about [Darth Vader](https://en.wikipedia.org/wiki/Darth_Vader).

You can also use the parse function to extract the macro expressions:

import { parse } from 'markdown-macros'

const macroExpressions = parse(content)

The result is an array of parsed macro expressions:

[
  {
    expression: '@MACRO:HELLO()',
    name: 'HELLO',
    args: [],
    rawArgs: '',
    index: 20,
    regExp: RegExp
  },
  {
    expression: "@MACRO:WIKI_URL('Darth_Vader')",
    name: 'WIKI_URL',
    args: [ 'Darth_Vader' ],
    rawArgs: "'Darth_Vader'",
    index: 84,
    regExp: RegExp
  }
]

💡 Please check the API documentation.

Now, let's try the remark, markdown-it, and marked plugins.

remark

import { remark } from 'remark'
import remarkPlugin from 'markdown-macros/remark'

const processor = remark()
  .use(remarkPlugin, {
    hello: {
      exec: () => 'Hello!'
    }
  })

const result = String(await processor.process('# @MACRO:HELLO()'))
// # Hello!

👀 See also remarkPlugin

markdown-it

import MarkdownIt from 'markdown-it'
import markdownItPlugin from 'markdown-macros/markdown-it'

const md = new MarkdownIt()

md.use(markdownItPlugin, {
  hello: {
    exec: () => 'Hello!'
  }
})

md.render('# @MACRO:HELLO()')
// <h1>Hello!</h1>

👀 See also markdownItPlugin

marked

import { Marked } from 'marked'
import markedPlugin from 'markdown-macros/marked'

const marked = new Marked()

marked.use(markedPlugin({
  hello: {
    exec: () => 'Hello!'
  }
}))

marked.parse('# @MACRO:HELLO()')
// <h1>Hello!</h1>

👀 See also markedPlugin

🤝 Contribute

You would like to contribute to this project? You are welcome!

First, please check:

👑 Author

Made with ❤ by Hervé Perchec

⚖️ License

MIT

📰 Changelog

See all changes to this project in the CHANGELOG.md file.


README.md - this file was auto generated with juisy README templater. Don't edit it.