draft-markup
Pipeline for using markup input (for example Markdown) with Draft-js.
Installation
$ npm i draft-markup --save
Usage
Initialize a syntax:
var DraftMarkup = ;var markdown = ; var draftMarkup = markdown;
Markdown to ContentState
Generate a ContentState blocks list for draft-js using toRawContent
:
var rawContent = draftMarkup;var blocks = draft;var content = draftContentState;
ContentState to Markdown
Output markdown from a ContentState using .toText
:
var rawContent = draft;var text = draftMarkup;
Markdown Support
This module uses the rules from kramed to parse Markdown, it supports the whole syntaxes (headings, paragraphs, lists, tables, footnotes, etc). But:
- Reference links are replaced by (resolved) links
- Custom ID for headings (
# My Title #{myID}
) are parsed and added as an entity in theheader-x
block. - Table are parsed as a block with inner entities for each rows/columns
Custom Rules
This module contains the markdown syntax, but you can write your custom set of rules or extend the existing ones.
var myRule = DraftMarkup ;
Create a new syntax inherited from the markdown one:
var mySyntax = DraftMarkup; // Add a new rulemySyntaxblocks; //Remove a rulemySyntaxblocks; // Replace a rulemySyntaxblocks;
Checkout the GitBook syntax as an example of custom rules extending a syntax.