# remark-macro

> A macro system for remarkjs

Latest version **1.0.7** (published 2018-10-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install remark-macro
pnpm add remark-macro
yarn add remark-macro
bun add remark-macro
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2018-10-10 |
| First published | 2018-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 19.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | virk |
| Maintainers | virk |
| Keywords | remark, unified, macros |

## Links

- npm: https://www.npmjs.com/package/remark-macro
- Repository: https://github.com/dimerapp/remark-macro
- Homepage: https://github.com/dimerapp/remark-macro#readme
- Issues: https://github.com/dimerapp/remark-macro/issues
- npm.io page: https://npm.io/package/remark-macro

## Dependencies (1)

- [unist-util-visit](https://npm.io/package/unist-util-visit.md) ^1.4.0

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 1.0.7 (latest) — 2018-10-10
- 1.0.6 — 2018-10-09
- 1.0.5 — 2018-07-29
- 1.0.4 — 2018-07-28
- 1.0.3 — 2018-03-26
- 1.0.2 — 2018-03-25
- 1.0.1 — 2018-03-24
- 1.0.0 — 2018-03-23

## README

<div align="center">
  <div>
    <img width="500" src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1532274184/Dimer_Readme_Banner_lyy7wv.svg" alt="Dimer App">
  </div>
  <br>
  <p>
    <a href="https://dimerapp.com/what-is-dimer">
      Dimer is an open source project and CMS to help you publish your documentation online.
    </a>
  </p>
  <br>
  <p>
    <sub>We believe every project/product is incomplete without documentation. <br /> We want to help you publish user facing documentation, without worrying <code>about tools or code</code> to write.</sub>
  </p>
  <br>
</div>

# 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('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>
*/
```

---
_Source: https://npm.io/package/remark-macro · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
