
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
draftjs-to-markdown
Advanced tools
A library for converting DraftJS editor content to markdown.
This is draft to markdown library I wrote for one of my projects. I am open-sourcing it so that others can also be benefitted from my work.
npm install draftjs-to-markdown
import draftToMarkdown from 'draftjs-to-markdown';
const rawContentState = convertToRaw(editorState.getCurrentContent());
const markup = draftToMarkdown(contentState);
Following is the list of conversions it supports:
Block Type | Markdown | |
---|---|---|
1 | header-one | # |
2 | header-two | ## |
3 | header-three | ### |
4 | header-four | #### |
5 | header-five | ##### |
6 | header-six | ###### |
7 | unordered-list-item | - |
8 | ordered-list-item | 1. |
9 | blockquote | > |
10 | unstyled |
It performs these additional changes to text of blocks:
- replace blank space in beginning and end of block with
- replace \n
with \s\s\n
- replace <
with <
- replace >
with >
Ordered and unordered list blocks with depths are appended with 4 blank spaces.
Converts inline styles BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, CODE, SUPERSCRIPT, SUBSCRIPT to corresponding markdown syntax: **, *, __, ~~, ``, <sup>, <sub>
.
Converts inline styles color, background-color, font-size, font-family to a span tag with inline style details:
<span style="color:xyz;font-size:xx">
. The inline styles should start with strings color
or font-size
like color-red
, color-green
or fontsize-12
, fontsize-20
.
Converts entity range of type link to :[Link Text](Link URL)
.
Converts atomic entity image to image tag using entity data src for image source: !(Image Source)
.
Converts embedded links to HTML iframe tags <iframe ... />.
For block level styles like text-alignment add <span>
with style
property around block content.
MIT.
FAQs
A library for draftjs to markdown conversion.
The npm package draftjs-to-markdown receives a total of 8,445 weekly downloads. As such, draftjs-to-markdown popularity was classified as popular.
We found that draftjs-to-markdown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.