Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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';
import { convertToRaw } from 'draft-js;
const rawContentState = convertToRaw(editorState.getCurrentContent());
const markup = draftToMarkdown(contentState, hashConfig, customEntityTransform, config);
The function parameters are:
contentState: Its instance of RawDraftContentState
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 are optional.
customEntityTransform: Its function to render custom defined entities by user, its also optional.
config: Object to pass configuration options.
{
blockTypesMapping : {/* mappings */},
emptyLineBeforeBlock : true
}
blockTypesMapping overrides the default markdown syntax. For example, to use an asterisk rather than a dash for unordered-list-item:
{
blockTypesMapping : {
'unordered-list-item': '* '
}
}
By default only one line break is added before a block. Pass emptyLineBeforeBlock: true
to add two line breaks before every block.
editorState is instance of DraftJS EditorState.
Following is the list of conversions it supports:
Convert block types to corresponding markdown syntax:
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 | code | |
11 | unstyled | `` |
It performs these additional changes to text of blocks:
\n
with \s\s\n
<
with <
>
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">
. (In the input JSON, 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 hashtags to :[hashtag](hashtag)
.
Converts atomic entity image to image tag using entity data src for image source: ![alt text](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.
Supports using function customEntityTransform
for custom draftjs entities. If present its call to generate markdown for entity. It can take 2 parameter:
entity
( object with { type, mutalibity, data})
text
text present in the block.
MIT.
FAQs
A library for draftjs to markdown conversion.
The npm package draftjs-to-markdown receives a total of 12,354 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.