# DraftJS TO HTML A library for converting DraftJS Editor content to plain HTML. This is draft to HTML library I wrote for one of my projects. I am open-sourcing it so that others can also be benefitted from my work. ## Installation `npm install draftjs-to-html` ## Usage ``` import { convertToRaw } from 'draft-js'; import draftToHtml from 'draftjs-to-html'; const rawContentState = convertToRaw(editorState.getCurrentContent()); const markup = draftToHtml( rawContentState, hashtagConfig, directional, customEntityTransform ); ``` The function parameters are: 1. **contentState**: Its instance of [RawDraftContentState](https://facebook.github.io/draft-js/docs/api-reference-data-conversion.html#content) 2. **hashConfig**: Its configuration object for hashtag, its required only if hashtags are used. If the object is not defined hashtags will be output as simple text in the markdown. ``` hashConfig = { trigger: '#', separator: ' ', } ``` Here trigger is character that marks starting of hashtag (default '#') and separator is character that separates characters (default ' '). These fields in hastag object are optional. 3. **directional**: Boolean, if directional is true text is aligned according to bidi algorithm. This is also optional. 4. **customEntityTransform**: Its function to render custom defined entities by user, its also optional. **editorState** is instance of DraftJS [EditorState](https://draftjs.org/docs/api-reference-editor-state.html#content). ## Supported conversions Following is the list of conversions it supports: 1. Convert block types to corresponding HTML tags: || Block Type | HTML Tag | | -------- | -------- | -------- | | 1 | header-one | h1 | | 2 | header-two | h2 | | 3 | header-three | h3 | | 4 | header-four | h4 | | 5 | header-five | h5 | | 6 | header-six | h6 | | 7 | unordered-list-item | ul | | 8 | ordered-list-item | ol | | 9 | blockquote | blockquote | | 10 | code | pre | | 11 | unstyled | p | It performs these additional changes to text of blocks: - replace blank space in beginning and end of block with ` ` - replace `\n` with `
` - replace `<` with `<` - replace `>` with `>` 2. Converts ordered and unordered list blocks with depths to nested structure of `