# @nuxt/markdown

> Nuxt-flavoured fork of @dimerapp/markdown

Latest version **0.0.21** (published 2019-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nuxt/markdown
pnpm add @nuxt/markdown
yarn add @nuxt/markdown
bun add @nuxt/markdown
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.21 |
| Published | 2019-08-27 |
| First published | 2019-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 19 |
| Unpacked size | 21.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jonas Galvez |
| Maintainers | aldarund, atinux, clarkdo, galvez, kevinmarrec, mannil, pi0 |
| Keywords | markdown, markdown-to-html, markdown-parser, nuxt, nuxtjs |

## Links

- npm: https://www.npmjs.com/package/@nuxt/markdown
- Repository: https://github.com/nuxt/markdown
- Homepage: https://github.com/nuxt/markdown#readme
- Issues: https://github.com/nuxt/markdown/issues
- npm.io page: https://npm.io/package/@nuxt/markdown

## Dependencies (19)

- [detab](https://npm.io/package/detab.md) ^2.0.2
- [unified](https://npm.io/package/unified.md) ^8.3.2
- [rehype-raw](https://npm.io/package/rehype-raw.md) ^4.0.1
- [remark-slug](https://npm.io/package/remark-slug.md) ^5.1.2
- [remark-macro](https://npm.io/package/remark-macro.md) ^1.0.7
- [remark-parse](https://npm.io/package/remark-parse.md) ^7.0.1
- [remark-rehype](https://npm.io/package/remark-rehype.md) ^5.0.0
- [unist-builder](https://npm.io/package/unist-builder.md) ^1.0.4
- [mdast-util-toc](https://npm.io/package/mdast-util-toc.md) ^4.2.0
- [rehype-sanitize](https://npm.io/package/rehype-sanitize.md) ^3.0.0
- [rehype-stringify](https://npm.io/package/rehype-stringify.md) ^6.0.0
- [unist-util-visit](https://npm.io/package/unist-util-visit.md) ^2.0.0
- [@mapbox/rehype-prism](https://npm.io/package/@mapbox/rehype-prism.md) ^0.3.1
- [mdast-util-to-string](https://npm.io/package/mdast-util-to-string.md) ^1.0.6
- [mdast-util-definitions](https://npm.io/package/mdast-util-definitions.md) ^1.2.4
- [rehype-sort-attributes](https://npm.io/package/rehype-sort-attributes.md) ^2.0.1
- [rehype-minify-whitespace](https://npm.io/package/rehype-minify-whitespace.md) ^2.0.4
- [remark-squeeze-paragraphs](https://npm.io/package/remark-squeeze-paragraphs.md) ^3.0.4
- [rehype-sort-attribute-values](https://npm.io/package/rehype-sort-attribute-values.md) ^2.0.1

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.0.21 (latest) — 2019-08-27
- 0.0.20 — 2019-08-19
- 0.0.19 — 2019-08-19
- 0.0.18 — 2019-08-19
- 0.0.17 — 2019-08-19
- 0.0.16 — 2019-08-19
- 0.0.15 — 2019-08-19
- 0.0.14 — 2019-08-19
- 0.0.13 — 2019-08-19
- 0.0.12 — 2019-08-19
- 0.0.11 — 2019-08-19
- 0.0.10 — 2019-07-14
- 0.0.9-c — 2019-07-14
- 0.0.9-b — 2019-07-08
- 0.0.9 — 2019-07-08
- … 8 more at https://npm.io/package/@nuxt/markdown/versions

## README

# @nuxt/markdown

A Nuxt-flavoured fork of [`@dimerapp/markdown`](https://github.com/dimerapp/markdown) that features granular control [unified](https://github.com/unifiedjs/unified) stream.

## Install

```sh
npm i @nuxt/markdown --save
```

## Usage

```js
import Markdown from '@nuxt/markdown'

const md = new Markdown({ toc: false, sanitize: false })
const contents = await md.toHTML(markdownSourceString)
```

## Processing layers

```js
import Markdown from '@nuxt/markdown'
import remarkContainer from 'remark-container'

const md = new Markdown({
  extend({ layers }) {
    layers['remark-container'] = remarkContainer
  }
})

const rendered = await md.toMarkup(markdownSourceString)
```

Assigning is equivalent to **pushing** to the **last second position** of the internal `layers` Array. 

This is because the last step is `rehype-stringify`, responsible for the final HTML output, but we still want to be able to customize/remove that if needed.

You can also use Array methods directly:

```js
const md = new Markdown({
  extend({ layers }) {
    layers.splice(pos, 0, ['remark-container', remarkContainer])
  }
})
```

This is the default `layers` Array provided to a `@nuxt/markdown` instance:

```js
const layers = [
  ['remark-parse', remarkParse],
  ['remark-slug', remarkSlug],
  ['remark-autolink-headings', autolinkHeadings],
  ['remark-macro', macroEngine.transformer],
  ['remark-squeeze-paragraphs', squeezeParagraphs],
  ['remark-rehype', remarkRehype, { allowDangerousHTML: true }],
  ['rehype-raw', rehypeRaw],
  ['rehype-prism', rehypePrism, { ignoreMissing: true }],
  ['rehype-stringify', rehypeStringify]
]
```

Each layer begins with an arbitrary id, to make addressing specific layers easier.

## Custom remark-rehype handlers

You can also pass in a `handlers` object to the `Markdown` constructor to define custom [remark-rehype](https://github.com/remarkjs/remark-rehype) handlers.

See a [list of available overridable handlers here](https://github.com/nuxt/markdown/tree/develop/src/handlers).

## Adding macros

**@nuxt/markdown** includes [remark-macro](https://github.com/dimerapp/remark-macro), a nifty library that adds macro support to Markdown files. To add macros, use the `extend()` function like in the previous examples:

```js
import Markdown from '@nuxt/markdown'

const md = new Markdown({
  extend({ macros }) {
    macros.alert = (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]
`

const rendered = await md.toMarkup(markdown)
```

Example taken from [dimerapp/remark-macro](https://github.com/dimerapp/remark-macro).

## NuxtPress roadmap

@nuxt/markdown was created mainly for [NuxtPress](https://nuxt.press) and is part of its **[roadmap](https://nuxt.press/en/roadmap/#roadmap)**.

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