markdown-draft-js
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -322,10 +322,14 @@ 'use strict'; | ||
// Escaping inline markdown characters | ||
character = character.replace(MARKDOWN_STYLE_CHARACTERS, '\\$1'); | ||
if (block.type !== 'code-block' && !openInlineStyles.find(function (style) { | ||
return style.style === 'CODE'; | ||
})) { | ||
// Escaping inline markdown characters | ||
character = character.replace(MARKDOWN_STYLE_CHARACTERS, '\\$1'); | ||
// Special escape logic for blockquotes and heading characters | ||
if (characterIndex === 0 && character === '#' && block.text[1] && block.text[1] === ' ') { | ||
character = character.replace('#', '\\#'); | ||
} else if (characterIndex === 0 && character === '>') { | ||
character = character.replace('>', '\\>'); | ||
// Special escape logic for blockquotes and heading characters | ||
if (characterIndex === 0 && character === '#' && block.text[1] && block.text[1] === ' ') { | ||
character = character.replace('#', '\\#'); | ||
} else if (characterIndex === 0 && character === '>') { | ||
character = character.replace('>', '\\>'); | ||
} | ||
} | ||
@@ -332,0 +336,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"author": "Rose Robertson", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -324,10 +324,12 @@ const TRAILING_WHITESPACE = /[ \u0020\t]*$/; | ||
// Escaping inline markdown characters | ||
character = character.replace(MARKDOWN_STYLE_CHARACTERS, '\\$1'); | ||
if (block.type !== 'code-block' && !openInlineStyles.find((style) => style.style === 'CODE')) { | ||
// Escaping inline markdown characters | ||
character = character.replace(MARKDOWN_STYLE_CHARACTERS, '\\$1'); | ||
// Special escape logic for blockquotes and heading characters | ||
if (characterIndex === 0 && character === '#' && block.text[1] && block.text[1] === ' ') { | ||
character = character.replace('#', '\\#'); | ||
} else if (characterIndex === 0 && character === '>') { | ||
character = character.replace('>', '\\>'); | ||
// Special escape logic for blockquotes and heading characters | ||
if (characterIndex === 0 && character === '#' && block.text[1] && block.text[1] === ' ') { | ||
character = character.replace('#', '\\#'); | ||
} else if (characterIndex === 0 && character === '>') { | ||
character = character.replace('>', '\\>'); | ||
} | ||
} | ||
@@ -334,0 +336,0 @@ |
@@ -267,2 +267,20 @@ import { markdownToDraft, draftToMarkdown } from '../src/index'; | ||
it ('doesn’t escape markdown characters in inline code blocks', function () { | ||
/* eslint-disable */ | ||
var rawObject = {"entityMap":{},"blocks":[{"key":"dvfr1","text":"such special code which contains *special* chars is so important","type":"unstyled","depth":0,"inlineStyleRanges":[{'offset':5,'length':43,'style':'CODE'}],"entityRanges":[],"data":{}}]}; | ||
/* eslint-enable */ | ||
var markdown = draftToMarkdown(rawObject); | ||
expect(markdown).toEqual('such `special code which contains *special* chars` is so important'); | ||
}); | ||
it ('doesn’t escape markdown characters in code blocks', function () { | ||
/* eslint-disable */ | ||
var rawObject = {"entityMap":{},"blocks":[{"key":"dvfr1","text":"such special _code_ which contains *special* chars *wow*","type":"code-block","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}]}; | ||
/* eslint-enable */ | ||
var markdown = draftToMarkdown(rawObject); | ||
expect(markdown).toEqual('```\nsuch special _code_ which contains *special* chars *wow*\n```'); | ||
}); | ||
it('handles blank lines with styled block types', function () { | ||
@@ -269,0 +287,0 @@ // draft-js can have blank lines that have block styles. |
100372
1937