MDX v1.0.0-alpha.0


Writing a plugin

For a full-fledged introduction to plugins it’s recommended to read the remark guides and about syntax trees.

Now let’s consider an example where we want to pass all headings through the title module to ensure consistent capitalization. We can use unist-util-visit to visit all headings and change the text nodes with title(text).

const title = require('title')
const visit = require('unist-util-visit')

module.exports = () => (tree, file) => {
  visit(tree, 'heading', node => {
    visit(node, 'text', textNode => {
      const text = textNode.value ? textNode.value.trim() : ''  
      textNode.value = title(text)
    })
  })
}