From e7c4a656b8ac247ee987dfc79225cdfa721c6fc0 Mon Sep 17 00:00:00 2001 From: Nico Schlumprecht Date: Fri, 18 Nov 2022 17:06:52 -0500 Subject: [PATCH] Use * instead of _ for italics This fixes issues converting text with italics in the middle of the word, for example aaaaaaitalicbbbb Or when the space at the end of the word is italicized: aaaaaitalic bbbb Or when mixing bold / italic / bold+italic aaaaitalicbolditalicitalicbbb I have tested rendering the resulting markdown with both ReactMarkdown (https://github.com/remarkjs/react-markdown) and on iOS with the builtin AttributedString to confirm it renders correctly --- packages/draft-js-export-markdown/src/stateToMarkdown.js | 2 +- packages/draft-js-export-markdown/test/test-cases.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/draft-js-export-markdown/src/stateToMarkdown.js b/packages/draft-js-export-markdown/src/stateToMarkdown.js index de48679c..ed3f1820 100644 --- a/packages/draft-js-export-markdown/src/stateToMarkdown.js +++ b/packages/draft-js-export-markdown/src/stateToMarkdown.js @@ -244,7 +244,7 @@ if (!content.length) { content = `++${content}++`; } if (style.has(ITALIC)) { - content = `_${content}_`; + content = `*${content}*`; } if (style.has(STRIKETHROUGH)) { // TODO: encode `~`? diff --git a/packages/draft-js-export-markdown/test/test-cases.txt b/packages/draft-js-export-markdown/test/test-cases.txt index 1d7450e7..bb16074f 100644 --- a/packages/draft-js-export-markdown/test/test-cases.txt +++ b/packages/draft-js-export-markdown/test/test-cases.txt @@ -20,11 +20,11 @@ asd **f** . >> Nested Inline Style {"entityMap":{},"blocks":[{"key":"9nc73","text":"BoldItalic","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":0,"length":10,"style":"BOLD"},{"offset":0,"length":10,"style":"ITALIC"}],"entityRanges":[]}]} -_**BoldItalic**_ +***BoldItalic*** >> Adjacent Inline Style {"entityMap":{},"blocks":[{"key":"9nc73","text":"BoldItalic","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":4,"length":6,"style":"BOLD"},{"offset":0,"length":4,"style":"ITALIC"}],"entityRanges":[]}]} -_Bold_**Italic** +*Bold***Italic** >> Image with alt {"entityMap":{"0":{"type":"IMAGE","mutability":"MUTABLE","data":{"src":"/a.jpg","alt":"x"}}},"blocks":[{"key":"f131g","text":"Hello World.","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":5,"length":1,"key":0}]}]}