Convert markdown to GitHub-style HTML using a common set of remark plugins
Перейти к файлу
dependabot[bot] de958a02f1
build(deps): bump http-cache-semantics from 4.1.0 to 4.1.1 (#62)
Bumps [http-cache-semantics](https://github.com/kornelski/http-cache-semantics) from 4.1.0 to 4.1.1.
- [Release notes](https://github.com/kornelski/http-cache-semantics/releases)
- [Commits](https://github.com/kornelski/http-cache-semantics/compare/v4.1.0...v4.1.1)

---
updated-dependencies:
- dependency-name: http-cache-semantics
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-03 22:53:37 -08:00
.circleci build: use cfa orb (#58) 2023-01-09 12:47:30 -08:00
.github chore: set @wg-ecosystem as CODEOWNERS (#60) 2023-01-31 13:23:04 -08:00
test feat: add `ignoreMissing` option to allow skip valid language checking (#27) 2020-05-13 00:39:48 +03:00
.gitignore fix: preserve HTML from source markdown strings (#20) 2019-09-17 10:21:11 -07:00
.releaserc.json ci: move to CircleCI (#13) 2019-07-24 08:51:06 -07:00
LICENSE chore: add LICENSE file to match package.json (#61) 2023-01-31 13:22:51 -08:00
index.d.ts feat: add `ignoreMissing` option to allow skip valid language checking (#27) 2020-05-13 00:39:48 +03:00
index.js feat: add `ignoreMissing` option to allow skip valid language checking (#27) 2020-05-13 00:39:48 +03:00
package.json build: use cfa orb (#58) 2023-01-09 12:47:30 -08:00
readme.md feat: add `ignoreMissing` option to allow skip valid language checking (#27) 2020-05-13 00:39:48 +03:00
yarn.lock build(deps): bump http-cache-semantics from 4.1.0 to 4.1.1 (#62) 2023-02-03 22:53:37 -08:00

readme.md

hubdown

CircleCI build status

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

Used by electron/i18n and electronjs.org.

unified processes content with syntax trees and transforms between different formats. remark and rehype are its markdown and HTML ecosystems. We use this because its performant and has a large collection of plugins. Primarily, unlike some other node markdown parsers that provide syntax highlighting capabilities, unified 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 and rehype plugins are used by hubdown:

Installation

npm install hubdown --save

Usage

hubdown exports a single function that returns a promise:

const hubdown = require('hubdown')

hubdown('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>'
}

Usage with Cache

hubdown's remark markdown parser is pretty fast, but things can start to slow down when you're processing hundreds or thousands of files. To make life easier in these situations you can use hubdown's optional cache, which stores preprocessed markdown for fast retrieval on subsequent runs.

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

const hubdown = require('hubdown')
const cache = require('level')('./my-hubdown-cache')

hubdown('I will be cached.', { cache }).then(doc => {
  console.log(doc)
})

API

hubdown(markdownString[, options])

Arguments:

  • markdownString String - (required)
  • options Object - (optional)
    • runBefore Array of remark plugins - Custom plugins to be run before the commonly used plugins listed above.
    • frontmatter Boolean - Whether or not to try to parse YML frontmatter in the file. Defaults to false.
    • cache LevelDB - An optional level instance in which to store preprocessed content. See Usage with Cache.
    • highlight - Object of rehype-highlight options.

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

npm install
npm test

License

MIT