# marky-markdown

> npm's markdown parser

Latest version **12.0.0** (published 2018-01-17) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install marky-markdown
pnpm add marky-markdown
yarn add marky-markdown
bun add marky-markdown
```

Provides the command `marky-markdown`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 12.0.0 |
| Published | 2018-01-17 |
| First published | 2014-12-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 26 |
| Known vulnerabilities | 2 (+15 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 402 |
| Author | Ashley Williams |
| Maintainers | revin, ag_dubs, soldair, bcoe, rockbot |
| Keywords | readme, gfm, github, formatted, markdown, md, documentation, syntax highlighting, html, npm |

## Links

- npm: https://www.npmjs.com/package/marky-markdown
- Repository: https://github.com/npm/marky-markdown
- Issues: https://github.com/npm/marky-markdown/issues
- npm.io page: https://npm.io/package/marky-markdown

## Dependencies (26)

- [innertext](https://npm.io/package/innertext.md) ^1.0.2
- [highlights](https://npm.io/package/highlights.md) ^3.2.0-candidate.1
- [similarity](https://npm.io/package/similarity.md) ^1.0.1
- [markdown-it](https://npm.io/package/markdown-it.md) ^8.4.0
- [is-plain-obj](https://npm.io/package/is-plain-obj.md) ^1.1.0
- [language-ini](https://npm.io/package/language-ini.md) ^1.7.0
- [property-ttl](https://npm.io/package/property-ttl.md) ^1.0.0
- [language-dart](https://npm.io/package/language-dart.md) ^0.1.1
- [language-glsl](https://npm.io/package/language-glsl.md) ^2.0.1
- [language-haxe](https://npm.io/package/language-haxe.md) ^0.2.1
- [language-rust](https://npm.io/package/language-rust.md) ^0.4.7
- [lodash.assign](https://npm.io/package/lodash.assign.md) ^4.0.2
- [lodash.pickby](https://npm.io/package/lodash.pickby.md) ^4.2.1
- [sanitize-html](https://npm.io/package/sanitize-html.md) ^1.17.0
- [github-slugger](https://npm.io/package/github-slugger.md) ^1.2.0
- [language-erlang](https://npm.io/package/language-erlang.md) ^2.0.0
- [language-stylus](https://npm.io/package/language-stylus.md) ^0.5.2
- [lodash.defaults](https://npm.io/package/lodash.defaults.md) ^4.0.1
- [highlights-tokens](https://npm.io/package/highlights-tokens.md) ^1.0.1
- [markdown-it-emoji](https://npm.io/package/markdown-it-emoji.md) ^1.3.0
- [atom-language-diff](https://npm.io/package/atom-language-diff.md) ^1.0.0
- [atom-language-nginx](https://npm.io/package/atom-language-nginx.md) ^0.6.1
- [github-url-to-object](https://npm.io/package/github-url-to-object.md) ^4.0.0
- [markdown-it-task-lists](https://npm.io/package/markdown-it-task-lists.md) ^2.0.1
- [markdown-it-expand-tabs](https://npm.io/package/markdown-it-expand-tabs.md) ^1.0.12
- [markdown-it-lazy-headers](https://npm.io/package/markdown-it-lazy-headers.md) ^0.1.3

## 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

- 12.0.0 (latest) — 2018-01-17
- 11.3.2 — 2017-09-28
- 11.3.1 — 2017-09-21
- 11.3.0 — 2017-09-19
- 11.2.0 — 2017-08-19
- 11.1.0 — 2017-08-19
- 11.0.0 — 2017-06-09
- 10.1.4 — 2017-06-08
- 10.1.3 — 2017-06-06
- 10.1.2 — 2017-06-06
- 10.1.1 — 2017-06-02
- 10.1.0 — 2017-06-02
- 10.0.1 — 2017-05-31
- 10.0.0 — 2017-05-30
- 9.0.3 — 2017-04-12
- … 56 more at https://npm.io/package/marky-markdown/versions

## README

# marky-markdown

[![Build Status](https://travis-ci.org/npm/marky-markdown.svg?branch=master)](https://travis-ci.org/npm/marky-markdown)
[![Code Climate](https://codeclimate.com/github/npm/marky-markdown/badges/gpa.svg)](https://codeclimate.com/github/npm/marky-markdown)
[![Dependency Status](https://david-dm.org/npm/marky-markdown.svg)](https://david-dm.org/npm/marky-markdown)
[![Pull Requests](https://img.shields.io/github/issues-pr/npm/marky-markdown.svg)](https://github.com/npm/marky-markdown/pulls)
[![Issues](https://img.shields.io/github/issues/npm/marky-markdown.svg)](https://github.com/npm/marky-markdown/issues)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)

`marky-markdown` is a markdown parser, written in NodeJS, that aims for
parity with [GitHub-style markdown]. It is built on top of [`markdown-it`],
a [CommonMark] markdown parser. You can use marky-markdown:

- [programmatically in NodeJS]
- [in your terminal]
- [in the browser] *does not yet support syntax highlighting

`marky-markdown` is the thing that parses package READMEs on
http://www.npmjs.com. If you see a markdown parsing bug there,
[file an issue here]!

[file an issue here]: https://github.com/npm/marky-markdown/issues
[GitHub-style markdown]: https://help.github.com/articles/basic-writing-and-formatting-syntax/
[CommonMark]: http://spec.commonmark.org/
[`markdown-it`]: https://github.com/markdown-it/markdown-it
[programmatically in NodeJS]: #programmatic-usage
[in your terminal]: #command-line-usage
[in the browser]: #in-the-browser

## Node Version Support

marky-markdown strives to support all LTS, current, and maintenance
versions of Node.js. When a version of Node.js is EOL, we will EOL
support for that version for marky-markdown.

For more information on Node.js LTS and support, click [here](https://github.com/nodejs/LTS).

- marky-markdown < `9.0.0` supports `0.10`, `0.12`, `iojs`, `4`, `5`
- marky-markdown >= `9.0.0` supports `0.12`, `4`, `6`

## Installation

```sh
npm install marky-markdown --save
```

## Programmatic Usage

marky-markdown exports a single function. For basic use, that function
takes a single argument: a string to convert.

```js
var marky = require("marky-markdown")
var html = marky("# hello, I'm markdown")
```

### Options

The exported function takes an optional options object
as its second argument:

```js
marky("some trusted string", {sanitize: false})
```

The default options are as follows:

```js
{
  sanitize: true,               // remove script tags and stuff
  nofollow: true,               // add rel=nofollow to all links
  linkify: true,                // turn orphan URLs into hyperlinks
  highlightSyntax: true,        // run highlights on fenced code blocks
  prefixHeadingIds: true,       // prevent DOM id collisions
  enableHeadingLinkIcons: true, // render icons inside generated section links
  serveImagesWithCDN: false,    // use npm's CDN to proxy images over HTTPS
  debug: false,                 // console.log() all the things
  package: null,                // npm package metadata,
  headingAnchorClass: 'anchor', // the classname used for anchors in headings.
  headingSvgClass: ['octicon']  // the class used for svg icon in headings.
}
```

### Low Level Parser Access

If you need lower level access to the markdown-it parser (to add your own
[markdown-it plugins](https://www.npmjs.com/search?q=markdown-it-plugin), for
example), you can call the `getParser` method:

```js
var parser = marky.getParser()
parser.use(someMarkdownItPlugin)
var html = parser.render("# markdown string")
```

`getParser` takes an optional `options` argument, the same format as the main
marky-markdown export function. If you omit it, it uses the same default options
described above.

When you're done customizing the parser, call `parser.render(markdown)` to
render to HTML.

## Command-line Usage

You can use marky-markdown to parse markdown files in the shell.
The easiest way to do this is to install globally:

```
npm i -g marky-markdown
marky-markdown some.md > some.html
```

## In the Browser

This module mostly works in the browser, with the exception of the `highlights` module.

You can `require('marky-markdown')` in scripts you browserify yourself,
or just use the standalone file in [dist/marky-markdown.js].

Here is an example using HTML5 to render text inside `<marky-markdown>` tags.

```html
<script src="marky-markdown.js"></script>

<marky-markdown>**Here** _is_ some [Markdown](https://github.com/)</marky-markdown>

<script>
  for (el of document.getElementsByTagName('marky-markdown')) {
    el.innerHTML = markyMarkdown(el.innerHTML, {highlightSyntax: false})
  }
</script>
```

Note: Usage with [webpack](https://webpack.github.io/) requires that your
`webpack.config.js` configure a loader (such as
[json-loader](https://github.com/webpack/json-loader)) for .json files. Also, you need to config `process.browser` in `webpack.config.js` when you target browser:

```js
  plugins: [
    new webpack.DefinePlugin({
      'process.browser': true
    })
  ],
```

## Tests

```sh
npm install
npm test
```

## What it does

- Parses markdown with [markdown-it](https://github.com/markdown-it/markdown-it), a fast and [commonmark-compliant](http://commonmark.org/) parser.
- Removes broken and malicious user input with [sanitize-html](https://www.npmjs.com/package/sanitize-html)
- Applies syntax highlighting to [GitHub-flavored code blocks](https://help.github.com/articles/creating-and-highlighting-code-blocks/) using the [highlights](https://www.npmjs.com/package/highlights) library from [Atom](https://atom.io/).
- Converts `:emoji:`-style [shortcuts](http://www.emoji-cheat-sheet.com/) to unicode emojis.
- Converts headings (h1, h2, etc) into anchored hyperlinks.
- Converts relative GitHub links to their absolute equivalents.
- Converts relative GitHub images sources to their GitHub raw equivalents.
- Converts insecure Gravatar URLs to HTTPS.
- Converts list items with leading `[ ]` and `[x]` into [GitHub-style task lists](https://github.com/blog/1825-task-lists-in-all-markdown-documents)
- Wraps embedded YouTube videos so they can be styled.
- Parses and sanitizes `package.description` as markdown.
- Applies CSS classes to redundant content that closely matches npm package name and description.

### npm packages

Pass in an npm `package` object to do stuff like rewriting relative URLs
to their absolute equivalent on GitHub, normalizing package metadata
with redundant readme content, etc

```js
var package = {
  name: "foo",
  description: "foo is a thing",
  repository: {
    type: "git",
    url: "https://github.com/kung/foo"
  }
}

marky(
  "# hello, I am the foo readme",
  {package: package}
)
```

## Dependencies

- [github-slugger](https://github.com/Flet/github-slugger): Generate a slug just like GitHub does for markdown headings
- [github-url-to-object](https://github.com/zeke/github-url-to-object): Extract user, repo, and other interesting properties from GitHub URLs
- [highlights](https://github.com/atom/highlights): Syntax highlighter
- [highlights-tokens](https://github.com/zeke/highlights-tokens): A list of the language tokens used by the Atom.app [highlights](https://www.npmjs.com/package/highlights) syntax highlighter
- [innertext](https://github.com/revin/innertext): Extract the `innerText` from a snippet of HTML
- [lodash](https://github.com/lodash/lodash): A utility library delivering consistency, customization, performance, &amp; extras.
- [markdown-it](https://github.com/markdown-it/markdown-it): Markdown-it - modern pluggable markdown parser.
- [markdown-it-emoji](https://github.com/markdown-it/markdown-it-emoji): Markdown-it-emoji extension for Markdown-it that parses markdown emoji syntax to unicode.
- [markdown-it-expand-tabs](https://github.com/revin/markdown-it-expand-tabs): Replace leading tabs with spaces in fenced code blocks
- [markdown-it-lazy-headers](https://github.com/Galadirith/markdown-it-lazy-headers): Lazy ATX headers plugin for markdown-it
- [markdown-it-task-lists](https://github.com/revin/markdown-it-task-lists): Render GitHub-style [task lists](https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments)
- [property-ttl](https://github.com/soldair/property-ttl): Save memory by nulling out a property after ttl if it has not been accessed
- [sanitize-html](https://github.com/punkave/sanitize-html): Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis
- [similarity](https://github.com/zeke/similarity): How similar are these two strings?

Extra syntax highlighting, in addition to what comes with [highlights](https://www.npmjs.com/package/highlights):

- [atom-language-diff](https://github.com/revin/atom-language-diff): Diff/patch files
- [atom-language-nginx](https://github.com/hnagato/atom-language-nginx): [NGINX](http://nginx.org/) configuration files
- [language-dart](https://github.com/Daegalus/atom-language-dart): [Dart](https://www.dartlang.org/) language
- [language-erlang](https://github.com/jonathanmarvens/atom-language-erlang): [Erlang](http://www.erlang.org/) language
- [language-glsl](https://github.com/hughsk/language-glsl): [OpenGL Shading Language](https://www.opengl.org/documentation/glsl/) files
- [language-haxe](https://github.com/theRemix/language-haxe): [Haxe](http://haxe.org/) language
- [language-ini](https://github.com/jacobbednarz/atom-language-ini): .ini configuration files
- [language-rust](https://github.com/zargony/atom-language-rust): [Rust](http://www.rust-lang.org/) language
- [language-stylus](https://github.com/matthojo/language-stylus): [Stylus](http://stylus-lang.com/) CSS preprocessor

## License

ISC

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