remark-macro
A macro system for remarkjs
Last updated 2 years ago by virk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install remark-macro 
SYNC missed versions from official npm registry.
Dimer App

Dimer is an open source project and CMS to help you publish your documentation online.


We believe every project/product is incomplete without documentation.
We want to help you publish user facing documentation, without worrying about tools or code to write.


Remark Macro

Add macros to remark parser

This library gives you an opportunity to define macros, which can be used inside the markdown as follows.

# Hello

Writing some markdown

[alert]
This is an alert message
[/alert]

The alert block is knows as a macro. By default the library will not parse this block. However, you can define a macro and then it will be parsed and all the contents will be forwarded to you.

const macro = require('remark-macro')()

macro.addMacro('alert', function (content, props) {
  assert.equal(content, 'This is an alert message')
  assert.deepEqual(props, {})
})

Installation

npm i --save remark-macro

Usage

const remark = require('remark')
const macro = require('remark-macro')()
const html = require('remark-html')

macro.addMacro('alert', function (content, props, { transformer, eat }) {
  return {
    type: 'AlertNode',
    data: {
      hName: 'div',
      hClassNames: ['alert alert-note'],
      hChildren: transformer.tokenizeBlock(content, eat.now())
    }
  } 
})

const markdown = `
# Hello world

[alert]
This is an alert
[/alert]
`

remark()
  .use(macro.transformer)
  .use(html)
  .process(markdown, function (error, result) {
    console.log(result.toString())
  })
  
/**
 <h1> Hello world </h1>
 <div class="alert alert-note"><p> This is an alert </p></div>
*/

Current Tags

  • 1.0.7                                ...           latest (2 years ago)

8 Versions

  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 8
This Week 80
This Month 8
Last Day 24
Last Week 167
Last Month 722
Dependencies (1)
Dev Dependencies (20)

Copyright 2014 - 2016 © taobao.org |