https://github.com/atinux/remark-macro
Adding support for block macros in remark
https://github.com/atinux/remark-macro
Last synced: 10 months ago
JSON representation
Adding support for block macros in remark
- Host: GitHub
- URL: https://github.com/atinux/remark-macro
- Owner: atinux
- License: mit
- Created: 2018-07-27T08:19:51.000Z (over 7 years ago)
- Default Branch: develop
- Last Pushed: 2018-07-27T08:20:31.000Z (over 7 years ago)
- Last Synced: 2025-03-19T20:45:34.835Z (10 months ago)
- Language: JavaScript
- Size: 111 KB
- Stars: 2
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
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.
```md
# 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.
```js
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
```js
const remark = require('remark')
const macro = require('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())
})
/**
Hello world
This is an alert
*/
```