smh-markdownerdeprecated

Convert Markdown to GitHub-style HTML

Usage no npm install needed!

<script type="module">
  import smhMarkdowner from 'https://cdn.skypack.dev/smh-markdowner';
</script>

README

markdowner

Convert markdown to GitHub-style HTML using a common set of remark plugins

remark is a performant markdown parser with a large plugin ecosystem. Unlike some other node markdown parsers that provide syntax highlighting capabilities, remark does not have any native C++ dependencies. This makes it easier to install and reduces the likelihood of system-dependent installation failures.

Plugins

The following remark plugins are used by markdowner:

Installation

yarn add smh-markdowner
# or
npm install smh-markdowner --save

Usage

markdowner exports a single function that returns a promise:

import { markdowner } from 'smh-markdowner'

markdowner('I am markdown').then(doc => {
  console.log(doc)
})

The resolved promise yields an object with a content property containing the parsed HTML:

{
  content: '<p>I am markdown</p>'
}

Using with Cache

NOTE: If you want uses cache module you need to install level dependency manually, you can make by npm install level

To use the cache, bring your own level instance and supply it as an option to markdown. This helps keep markdowner lean on (native) dependencies for users who don't need the cache

import { markdowner } from 'smh-markdowner'
const cache = require('level')('./my-cache')

markdowner('This is cached.', {cache}).then(doc => {
  console.log(doc)
})

API

markdowner(markdownString, {options})

Arguments:

  • markdownString String - (required)
  • options Object - (optional)
    • frontmatter Boolean - Whether or not to try to parse YML frontmatter in the file. Defaults to false.
    • cache Map - An optional level instance in which to store preprocessed content.
    • toc Boolean - Whether or not to try generate Table of Contents of markdown file.

Returns a promise. The resolved object looks like this:

{
  content: 'HTML goes here'
}

If YML frontmatter is parsed, those properties will be present on the object too:

{
  title: 'The Feminine Mystique',
  author: 'Betty Friedan',
  content: '<p>The Feminine Mystique is a book written by Betty Friedan which is widely credited with sparking the  beginning of second-wave feminism in the United States.</p>'
}

Tests

yarn
yarn test

License

MIT