metacran/marky-markdown

Name: marky-markdown

Owner: metacran

Description: The thing npmjs.com uses to clean up READMEs and other markdown files

Created: 2015-05-16 14:30:20.0

Updated: 2018-02-07 04:29:59.0

Pushed: 2018-02-07 04:29:30.0

Homepage: http://npm.im/marky-markdown

Size: 1280

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

marky-markdown

Build Status Code Climate Dependency Status Pull Requests Issues Conventional Commits

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:

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!

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.

Installation
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.

marky = require("marky-markdown")
html = marky("# hello, I'm markdown")
Options

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

y("some trusted string", {sanitize: false})

The default options are as follows:


nitize: true,               // remove script tags and stuff
follow: true,               // add rel=nofollow to all links
nkify: true,                // turn orphan URLs into hyperlinks
ghlightSyntax: true,        // run highlights on fenced code blocks
efixHeadingIds: true,       // prevent DOM id collisions
ableHeadingLinkIcons: true, // render icons inside generated section links
rveImagesWithCDN: false,    // use npm's CDN to proxy images over HTTPS
bug: false,                 // console.log() all the things
ckage: null,                // npm package metadata,
adingAnchorClass: 'anchor', // the classname used for anchors in headings.
adingSvgClass: ['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, for example), you can call the getParser method:

parser = marky.getParser()
er.use(someMarkdownItPlugin)
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:

i -g marky-markdown
y-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.

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

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

ipt>
r (el of document.getElementsByTagName('marky-markdown')) {
el.innerHTML = markyMarkdown(el.innerHTML, {highlightSyntax: false})

ript>

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

ugins: [
new webpack.DefinePlugin({
  'process.browser': true
})

Tests
install
test
What it does
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

package = {
me: "foo",
scription: "foo is a thing",
pository: {
type: "git",
url: "https://github.com/kung/foo"



y(
 hello, I am the foo readme",
ackage: package}

Dependencies

Extra syntax highlighting, in addition to what comes with highlights:

License

ISC


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.