Naboo's Podracing Misadventure

    posthtml-markdownit

    1.2.3 • Public • Published

    posthtml-markdownit

    Transform markdown using markdown-it

    Version License Build Downloads

    Introduction

    This plugin converts Markdown to HTML using markdown-it.

    Before:

    <markdown>
      # Heading 1
      ---
     
      Paragraph with some text
     
      *Italic*
      __Bold__
     
      - List item 1
      - List item 2
      - List item 3
    </markdown>

    After:

    <h1>Heading 1</h1>
    <hr>
    <p>Paragraph with some text</p>
    <p><em>Italic</em>
    <strong>Bold</strong></p>
    <ul>
    <li>List item 1</li>
    <li>List item 2</li>
    <li>List item 3</li>
    </ul>

    Install

    $ npm i -D posthtml-markdownit
    

    Usage

    const posthtml = require('posthtml')
    const markdown = require('posthtml-markdownit')
     
    posthtml([
        markdown()
      ])
      .process('<markdown># Test</markdown>')
      .then(result => console.log(result.html))
     
      // <h1>Test</h1>

    Importing files

    You can import and render Markdown files:

    Before:

    <markdown src="./README.md">
      # Imported
    </markdown>

    After:

    <!-- contents of README.md here -->
    <h1>Imported</h1>

    Syntax

    Tags

    Both <markdown> and <md> tags are suported.

    Before:

    <md>
      # Heading 1
    </md>

    After:

    <h1>Heading 1</h1>

    By default, the tags are removed. See the tag attribute if you need a wrapping tag around your Markdown content.

    Attributes

    You can also use markdown or md attributes on any element:

    Before:

    <div md>
      # Heading 1
    </div>

    After:

    <h1>Heading 1</h1>

    tag

    You can use a tag attribute to wrap the resulting markup in a tag:

    Before:

    <md tag="section">
      # Heading 1
    </md>

    After:

    <section>
      <h1>Heading 1</h1>
    </section>

    Options

    root

    Type: string
    Default: ./

    A path relative to which markdown files are imported.

    encoding

    Type: string
    Default: utf8

    Encoding for imported Markdown files.

    markdownit

    Type: object
    Default: {}

    Options passed to markdown-it. See the available options.

    plugins

    Type: array
    Default: []

    Plugins for markdown-it.

    Example:

    markdown({
      plugins: [{
        plugin: require('markdown-it-emoji'),
        options: {} // Options for markdown-it-emoji
      }]
    })

    Install

    npm i posthtml-markdownit

    DownloadsWeekly Downloads

    2,368

    Version

    1.2.3

    License

    MIT

    Unpacked Size

    8.1 kB

    Total Files

    4

    Last publish

    Collaborators

    • scrum
    • thecomputerm
    • cossssmin