@honkit/markup-it
TypeScript icon, indicating that this package has built-in type declarations

5.1.4 • Public • Published

@honkit/markup-it

@honkit/markup-it is a JavaScript library to parse and modify markuped content (for example Markdown) using an intermediate format backed by an immutable model.

@honkit/markup-it is fork of markup-it@2.2.0

  • Less dependency
  • For stability

Installation

$ npm i @honkit/markup-it  --save

Usage

Initialize a syntax:

var MarkupIt = require('@honkit/markup-it');
var markdownSyntax = require('@honkit/markup-it/syntaxes/markdown');
var htmlSyntax = require('@honkit/markup-it/syntaxes/html');

var markdown = new MarkupIt(markdownSyntax);
var html = new MarkupIt(htmlSyntax);

Parse a text

var content = markdown.toContent('Hello **World**');

Render content to HTML/Markdown

// Render back to markdown:
var textMd = markdown.toText(content);

// Render to HTML
var textHtml = html.toText(content);

Convert HTML into Markdown

var content = html.toContent('Hello <b>World</b>');
var textMd = markdown.toText(content);

Extend Syntax

This module contains the markdown syntax, but you can write your custom syntax or extend the existing ones.

Create rules

var myRule = MarkupIt.Rule(DraftMarkup.BLOCKS.HEADING_1)
    .regExp(/^<h1>(\S+)<\/h1>/, function(state, match) {
        return {
            tokens: state.parseAsInline(match[1])
        };
    })
    .toText(function(state, token) {
        return '<h1>' + state.renderAsInline(token) + '</h1>';
    });

Custom Syntax

Create a new syntax inherited from the markdown one:

var mySyntax = markdownSyntax.addBlockRules(myRule);

License

Apache-2.0

It includes Samy Pesse and GitBook works.

Package Sidebar

Install

npm i @honkit/markup-it

Weekly Downloads

10

Version

5.1.4

License

Apache-2.0

Unpacked Size

241 kB

Total Files

246

Last publish

Collaborators

  • azu
  • honkitbuild