{"id":16489061,"url":"https://github.com/thundernet8/draftjs-to-html-fork","last_synced_at":"2026-05-13T04:37:43.766Z","repository":{"id":57216015,"uuid":"107578320","full_name":"thundernet8/draftjs-to-html-fork","owner":"thundernet8","description":"🙇 draftjs raw content to html convertor with code highlight support","archived":false,"fork":false,"pushed_at":"2017-10-26T14:59:49.000Z","size":75,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-12T13:13:14.814Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thundernet8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-19T17:33:06.000Z","updated_at":"2023-01-06T05:02:24.000Z","dependencies_parsed_at":"2022-08-26T13:31:42.414Z","dependency_job_id":null,"html_url":"https://github.com/thundernet8/draftjs-to-html-fork","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2Fdraftjs-to-html-fork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2Fdraftjs-to-html-fork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2Fdraftjs-to-html-fork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2Fdraftjs-to-html-fork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thundernet8","download_url":"https://codeload.github.com/thundernet8/draftjs-to-html-fork/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240280984,"owners_count":19776418,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T13:42:52.760Z","updated_at":"2026-05-13T04:37:43.718Z","avatar_url":"https://github.com/thundernet8.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# draftjs-to-html-fork\n\ndraftjs raw content to html convertor with code highlight handling support.\n\n# Note\n\nThis is a fork and modified verision of draftjs-to-html package, the very most change is add code highlight support.\n\nThe `code` block will wrapped with `\u003cpre class=\"draft2html--pre\"\u003e\u003ccode class=\"_lang_default draft2html--code\"\u003e` and `\u003c/code\u003e\u003c/pre\u003e`. And the source code text will treated by prismjs library. What more you should do is to choose a code highlight stylesheet file as you like from [prismjs](http://prismjs.com/). The [highlightStyleSample.css](highlightStyleSample.css) is one of them.\n\n## Installation\n\n`npm install draftjs-to-html-fork`\n\n## Usage\n\n```\nimport { convertToRaw } from 'draft-js';\nimport draftToHtml from 'draftjs-to-html-fork';\n\nconst rawContentState = convertToRaw(editorState.getCurrentContent());\n\nconst markup = draftToHtml(\n  contentState, \n  hashtagConfig, \n  directional, \n  customEntityTransform\n);\n```\nThe function parameters are:\n\n1. **contentState**: Its instance of  [RawDraftContentState](https://facebook.github.io/draft-js/docs/api-reference-data-conversion.html#content)\n\n2. **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.\n    ```\n    hashConfig = {\n      trigger: '#',\n      separator: ' ',\n    }\n    ```\n    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.\n\n3. **directional**: Boolean, if directional is true text is aligned according to bidi algorithm. This is also optional.\n\n4. **customEntityTransform**: Its function to render custom defined entities by user, its also optional.\n\n   **editorState** is instance of DraftJS               [EditorState](https://draftjs.org/docs/api-reference-editor-state.html#content).\n\n## Supported conversions\nFollowing is the list of conversions it supports:\n\n1. Convert block types to corresponding HTML tags:\n\n    || Block Type | HTML Tag |\n    | -------- | -------- | -------- |\n    | 1 | header-one | h1 |\n    | 2 | header-two | h2 |\n    | 3 | header-three | h3 |\n    | 4 | header-four | h4 |\n    | 5 | header-five | h5 |\n    | 6 | header-six | h6 |\n    | 7 | unordered-list-item | ul |\n    | 8 | ordered-list-item | ol |\n    | 9 | blockquote | blockquote |\n    | 10 | code | pre |\n    | 11 | unstyled | p |\n\n    It performs these additional changes to text of blocks:\n    - replace blank space in beginning and end of block with `\u0026nbsp;`\n    - replace `\\n` with `\u003cbr\u003e`\n    - replace `\u003c` with `\u0026lt;`\n    - replace `\u003e` with `\u0026gt;`\n\n\n2. Converts ordered and unordered list blocks with depths to nested structure of `\u003cul\u003e, \u003col\u003e` and `\u003cli\u003e`.\n\n3. Converts inline styles BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, CODE, SUPERSCRIPT, SUBSCRIPT to corresponding HTML tags: `\u003cstrong\u003e, \u003cem\u003e, \u003cins\u003e, \u003ccode\u003e, \u003csup\u003e, \u003csub\u003e`.\n\n4. Converts inline styles color, background-color, font-size, font-family to a span tag with inline style details:\n`\u003cspan style=\"color:xyz;font-size:xx\"\u003e`. (The inline styles in JSON object should start with strings `color` or `font-size` like `color-red`, `color-green` or `fontsize-12`, `fontsize-20`).\n\n5. Converts entity range of type link to anchor tag using entity data url for href, target for target: `\u003ca href=\"url\" target=\"_self\"\u003etext\u003c/a\u003e`. Default target is `_self`.\n\n6. Converts entity range of type mention to anchor tag using entity data url for href and value for data-value, it also adds class to it: `\u003ca href=\"url\" class=\"wysiwyg-mention\" data-mention data-value=\"value\"\u003etext\u003c/a\u003e`.\n\n7. Converts atomic entity image to image tag using entity data src for image source, and if present alt, alignment, height, width also: `\u003cimg src=\"src\" alt=\"alt_text\" style=\"float: left, height: 50px; width: 50px\"/\u003e`.\n\n8. Converts embedded links to iFrames, using width, height and src from entity data. `\u003ciframe width=\"width\" height=\"height\" src=\"src\" frameBorder=\"0\"\u003e\u003c/iframe\u003e`\n\n9. Converts hashtags to anchor tag: `\u003ca href=\"#tag\" class=\"wysiwyg-hashtag\"\u003e#tag\u003c/a\u003e`.\n\n9. `customEntityTransform` can be used for transformation of a custom entity block to html. If present its call to generate html for entity. It can take 2 parameter:\n   1. `entity` ( object with { type, mutalibity, data})\n   2. `text` text present in the block.\n\n10. Adding style property to block tag for block level styles like text-align: `\u003cp style=\"text-align: right\"\u003etext\u003c/p\u003e`.\n\n11. RTL, if directional function parameter is true, generated blocks have property `dir = \"auto\"` thus they get aligned according to bidi algorithm.\n\n## License\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthundernet8%2Fdraftjs-to-html-fork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthundernet8%2Fdraftjs-to-html-fork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthundernet8%2Fdraftjs-to-html-fork/lists"}