New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

markdown-draft-js

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-draft-js - npm Package Compare versions

Comparing version 0.4.3 to 0.4.4

35

lib/draft-to-markdown.js

@@ -186,3 +186,4 @@ 'use strict';

function renderBlock(block, index, rawDraftObject, options) {
var openInlineStyles = [];
var openInlineStyles = [],
markdownToAdd = [];
var markdownString = '',

@@ -256,4 +257,8 @@ customStyleItems = options.styleItems || {},

if (customStyleItems[style.style] || StyleItems[style.style]) {
markdownString += (customStyleItems[style.style] || StyleItems[style.style]).open();
openInlineStyles.push(style);
var styleToAdd = (customStyleItems[style.style] || StyleItems[style.style]).open();
markdownToAdd.push({
type: 'style',
style: style,
value: styleToAdd
});
}

@@ -268,3 +273,7 @@ }

if (customEntityItems[entity.type] || EntityItems[entity.type]) {
markdownString += (customEntityItems[entity.type] || EntityItems[entity.type]).open(entity);
var entityToAdd = (customEntityItems[entity.type] || EntityItems[entity.type]).open(entity);
markdownToAdd.push({
type: 'entity',
value: entityToAdd
});
}

@@ -274,2 +283,20 @@ }

// These are all the opening entity and style types being added to the markdown string for this loop
// we store in an array and add here because if the character is WS character, we want to hang onto it and not apply it until the next non-whitespace
// character before adding the markdown, since markdown doesn’t play nice with leading whitespace (eg '** bold**' is no good, whereas ' **bold**' is good.)
if (character !== ' ' && markdownToAdd.length) {
markdownString += markdownToAdd.map(function (item) {
return item.value;
}).join('');
markdownToAdd.forEach(function (item) {
if (item.type === 'style') {
// We hang on to this because we may need to close it early and then re-open if there are nested styles being opened and closed.
openInlineStyles.push(item.style);
}
});
markdownToAdd = [];
}
markdownString += character;

@@ -276,0 +303,0 @@ });

2

package.json

@@ -5,3 +5,3 @@ {

"author": "Rose Robertson",
"version": "0.4.3",
"version": "0.4.4",
"license": "MIT",

@@ -8,0 +8,0 @@ "repository": {

@@ -188,3 +188,4 @@ const TRAILING_WHITESPACE = /[ |\u0020|\t]*$/;

function renderBlock(block, index, rawDraftObject, options) {
var openInlineStyles = [];
var openInlineStyles = [],
markdownToAdd = [];
var markdownString = '',

@@ -258,4 +259,8 @@ customStyleItems = options.styleItems || {},

if ((customStyleItems[style.style] || StyleItems[style.style])) {
markdownString += (customStyleItems[style.style] || StyleItems[style.style]).open();
openInlineStyles.push(style);
var styleToAdd = (customStyleItems[style.style] || StyleItems[style.style]).open();
markdownToAdd.push({
type: 'style',
style: style,
value: styleToAdd
});
}

@@ -270,3 +275,7 @@ }

if (customEntityItems[entity.type] || EntityItems[entity.type]) {
markdownString += (customEntityItems[entity.type] || EntityItems[entity.type]).open(entity);
var entityToAdd = (customEntityItems[entity.type] || EntityItems[entity.type]).open(entity);
markdownToAdd.push({
type: 'entity',
value: entityToAdd
});
}

@@ -276,2 +285,20 @@ }

// These are all the opening entity and style types being added to the markdown string for this loop
// we store in an array and add here because if the character is WS character, we want to hang onto it and not apply it until the next non-whitespace
// character before adding the markdown, since markdown doesn’t play nice with leading whitespace (eg '** bold**' is no good, whereas ' **bold**' is good.)
if (character !== ' ' && markdownToAdd.length) {
markdownString += markdownToAdd.map(function (item) {
return item.value;
}).join('');
markdownToAdd.forEach(function (item) {
if (item.type === 'style') {
// We hang on to this because we may need to close it early and then re-open if there are nested styles being opened and closed.
openInlineStyles.push(item.style);
}
});
markdownToAdd = [];
}
markdownString += character;

@@ -278,0 +305,0 @@ });

import { markdownToDraft, draftToMarkdown } from '../src/index';
describe('draftToMarkdown', function () {
it('renders inline styled text with leading whitespace correctly', function () {
/* eslint-disable */
var rawObject = {"entityMap":{},"blocks":[{"key":"dvfr1","text":"Test Bold Text Test","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":4,"length":10,"style":"BOLD"}],"entityRanges":[],"data":{}}]};
/* eslint-enable */
var markdown = draftToMarkdown(rawObject);
expect(markdown).toEqual('Test **Bold Text** Test');
});
it('renders inline styled text with trailing whitespace correctly', function () {

@@ -5,0 +14,0 @@ /* eslint-disable */

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc