npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

draftjs-to-markdown-imagefix

v0.4.4

Published

A library for draftjs to markdown conversion.

Downloads

2

Readme

DraftJS TO Markdown:imageFix - fix for draft-js-image-plugin

This is forked repository of DraftJS TO Markdown.

When DraftJS TO Markdown used with draft-js-image-plugin, it does not convert image to markdown because it checks whether an entity's type is 'IMAGE'. but draft-js-image-plugin saves entity type as 'image' so it doesn't work.

Therefore I simply eased case sensitivity when converting entity to markdown.

DraftJS TO Markdown

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.

Installation

npm install draftjs-to-markdown

Usage

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:

  1. contentState: Its instance of RawDraftContentState

  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 are optional.

  3. customEntityTransform: Its function to render custom defined entities by user, its also optional.

  4. 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.

Supported conversions

Following is the list of conversions it supports:

  1. 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:

    • replace blank space in beginning and end of block with  
    • replace \n with \s\s\n
    • replace < with &lt;
    • replace > with &gt;
  2. Ordered and unordered list blocks with depths are appended with 4 blank spaces.

  3. Converts inline styles BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, CODE, SUPERSCRIPT, SUBSCRIPT to corresponding markdown syntax: **, *, __, ~~, ``, <sup>, <sub>.

  4. 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).

  5. Converts entity range of type link to :[Link Text](Link URL).

  6. Converts hashtags to :[hashtag](hashtag).

  7. Converts atomic entity image to image tag using entity data src for image source: ![alt text](Image Source).

  8. Converts embedded links to HTML iframe tags <iframe ... />.

  9. For block level styles like text-alignment add <span> with style property around block content.

  10. Supports using function customEntityTransform for custom draftjs entities. If present its call to generate markdown for entity. It can take 2 parameter:

  11. entity ( object with { type, mutalibity, data})

  12. text text present in the block.

License

MIT.