From 7bc75d095bcdae0a85d95ed9d0c9188a89136805 Mon Sep 17 00:00:00 2001 From: Erez Rokah Date: Wed, 3 Jun 2020 13:16:24 +0300 Subject: [PATCH] fix(widget-markdown): don't strip new lines from text nodes (#3813) --- .../__snapshots__/parser.spec.js.snap | 24 ++++++++++++------- .../src/serializers/index.js | 2 +- .../src/serializers/remarkSlate.js | 10 +------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/netlify-cms-widget-markdown/src/MarkdownControl/__tests__/__snapshots__/parser.spec.js.snap b/packages/netlify-cms-widget-markdown/src/MarkdownControl/__tests__/__snapshots__/parser.spec.js.snap index 36df8dab..c11df3ea 100644 --- a/packages/netlify-cms-widget-markdown/src/MarkdownControl/__tests__/__snapshots__/parser.spec.js.snap +++ b/packages/netlify-cms-widget-markdown/src/MarkdownControl/__tests__/__snapshots__/parser.spec.js.snap @@ -32,7 +32,8 @@ Object { }, ], "object": "text", - "text": "Note: Feel free to play with this page. Unlike regular notes, this doesn't automatically save itself.", + "text": "Note: Feel free to play with this page. Unlike regular notes, this doesn't +automatically save itself.", }, ], "object": "block", @@ -52,7 +53,8 @@ Object { "nodes": Array [ Object { "object": "text", - "text": "Paragraphs can be written like so. A paragraph is the basic block of Markdown. A paragraph is what text will turn into when there is no reason it should + "text": "Paragraphs can be written like so. A paragraph is the basic block of Markdown. +A paragraph is what text will turn into when there is no reason it should become anything else.", }, ], @@ -76,7 +78,8 @@ become anything else.", }, Object { "object": "text", - "text": " and ", + "text": " and +", }, Object { "marks": Array [ @@ -298,7 +301,8 @@ uses a fixed-width font.", "nodes": Array [ Object { "object": "text", - "text": "Here is a quote. What this is should be self explanatory. Quotes are automatically indented when they are used.", + "text": "Here is a quote. What this is should be self explanatory. Quotes are +automatically indented when they are used.", }, ], "object": "block", @@ -322,7 +326,8 @@ uses a fixed-width font.", "nodes": Array [ Object { "object": "text", - "text": "There are six levels of headings. They correspond with the six levels of HTML headings. You've probably noticed them already in the page. Each level down + "text": "There are six levels of headings. They correspond with the six levels of HTML +headings. You've probably noticed them already in the page. Each level down uses one more hash character.", }, ], @@ -384,7 +389,8 @@ uses one more hash character.", "nodes": Array [ Object { "object": "text", - "text": "Of course, demonstrating what headings look like messes up the structure of the page.", + "text": "Of course, demonstrating what headings look like messes up the structure of the +page.", }, ], "object": "block", @@ -394,7 +400,8 @@ uses one more hash character.", "nodes": Array [ Object { "object": "text", - "text": "I don't recommend using more than three or four levels of headings here, because, when you're smallest heading isn't too small, and you're largest + "text": "I don't recommend using more than three or four levels of headings here, +because, when you're smallest heading isn't too small, and you're largest heading isn't too big, and you want each size up to look noticeably larger and more important, there there are only so many sizes that you can use.", }, @@ -618,7 +625,8 @@ more important, there there are only so many sizes that you can use.", "nodes": Array [ Object { "object": "text", - "text": "There's actually a lot more to Markdown than this. See the official introduction and syntax for more information. However, be aware that this is + "text": "There's actually a lot more to Markdown than this. See the official +introduction and syntax for more information. However, be aware that this is not using the official implementation, and this might work subtly differently in some of the little things.", }, diff --git a/packages/netlify-cms-widget-markdown/src/serializers/index.js b/packages/netlify-cms-widget-markdown/src/serializers/index.js index 3f0be220..de4711b8 100644 --- a/packages/netlify-cms-widget-markdown/src/serializers/index.js +++ b/packages/netlify-cms-widget-markdown/src/serializers/index.js @@ -158,7 +158,7 @@ export const markdownToHtml = (markdown, { getAsset, resolveWidget } = {}) => { const html = unified() .use(rehypeToHtml, { - allowDangerousHTML: true, + allowDangerousHtml: true, allowDangerousCharacters: true, closeSelfClosing: true, entities: { useNamedReferences: true }, diff --git a/packages/netlify-cms-widget-markdown/src/serializers/remarkSlate.js b/packages/netlify-cms-widget-markdown/src/serializers/remarkSlate.js index 833cd85f..f11ae0a3 100644 --- a/packages/netlify-cms-widget-markdown/src/serializers/remarkSlate.js +++ b/packages/netlify-cms-widget-markdown/src/serializers/remarkSlate.js @@ -284,16 +284,8 @@ export default function remarkToSlate({ voidCodeBlock } = {}) { return createBlock(typeMap[node.type], nodes, { data }); } - /** - * Text - * - * Text nodes contain plain text. We remove newlines because they don't - * carry meaning for a rich text editor - a break in rich text would be - * expected to result in a break in output HTML, but that isn't the case. - * To avoid this confusion we remove them. - */ case 'text': { - const text = node.value.replace(/\n/, ' '); + const text = node.value; return createText(text); }