From eca500880dd1b7a448b7d91a184eb8f43bb187c7 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 17 Feb 2018 19:28:24 +0000 Subject: [PATCH] All: Convert new lines in tables to BR tag, and added support for HTML tags in Markdown viewers --- ReactNativeClient/lib/MdToHtml.js | 5 +++++ ReactNativeClient/lib/import-enex-md-gen.js | 9 +++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ReactNativeClient/lib/MdToHtml.js b/ReactNativeClient/lib/MdToHtml.js index f838558ce..f41e78d7f 100644 --- a/ReactNativeClient/lib/MdToHtml.js +++ b/ReactNativeClient/lib/MdToHtml.js @@ -208,6 +208,8 @@ class MdToHtml { openTag = null; } else if (isInlineCode) { openTag = null; + } else if (tag && t.type.indexOf('html_inline') >= 0) { + openTag = null; } else if (tag && t.type.indexOf('_open') >= 0) { openTag = tag; } else if (tag && t.type.indexOf('_close') >= 0) { @@ -266,6 +268,8 @@ class MdToHtml { if (t.type === 'image') { if (tokenContent) attrs.push(['title', tokenContent]); output.push(this.renderImage_(attrs, options)); + } else if (t.type === 'html_inline') { + output.push(t.content); } else if (t.type === 'softbreak') { output.push('
'); } else if (t.type === 'hr') { @@ -351,6 +355,7 @@ class MdToHtml { const md = new MarkdownIt({ breaks: true, linkify: true, + html: true, }); // This is currently used only so that the $expression$ and $$\nexpression\n$$ blocks are translated diff --git a/ReactNativeClient/lib/import-enex-md-gen.js b/ReactNativeClient/lib/import-enex-md-gen.js index c7cf6e343..e0e78ea91 100644 --- a/ReactNativeClient/lib/import-enex-md-gen.js +++ b/ReactNativeClient/lib/import-enex-md-gen.js @@ -617,10 +617,6 @@ function enexXmlToMdArray(stream, resources) { }); } -function removeTableCellNewLines(cellText) { - return cellText.replace(/\n+/g, " "); -} - function tableHasSubTables(table) { for (let trIndex = 0; trIndex < table.lines.length; trIndex++) { const tr = table.lines[trIndex]; @@ -689,8 +685,9 @@ function drawTable(table) { line.push(BLOCK_CLOSE); } else { // Regular table rendering - // A cell in a Markdown table cannot have new lines so remove them - const cellText = removeTableCellNewLines(processMdArrayNewLines(td.lines)); + // A cell in a Markdown table cannot have actual new lines so replace + // them with
, which are supported by the markdown renderers. + const cellText = processMdArrayNewLines(td.lines).replace(/\n+/g, "
"); const width = Math.max(cellText.length, 3); line.push(stringPadding(cellText, width, ' ', stringPadding.RIGHT));