From 2e32211a2820dc1eef3e065824a2c33595090b37 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 14 May 2018 23:04:40 +0100 Subject: [PATCH] HtmlToMd: Fix conversion of tables --- CliClient/tests/html_to_md/table1.html | 12 ++++++++++++ CliClient/tests/html_to_md/table1.md | 5 +++++ ReactNativeClient/lib/import-enex-md-gen.js | 10 ++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 CliClient/tests/html_to_md/table1.html create mode 100644 CliClient/tests/html_to_md/table1.md diff --git a/CliClient/tests/html_to_md/table1.html b/CliClient/tests/html_to_md/table1.html new file mode 100644 index 0000000000..edeb12810c --- /dev/null +++ b/CliClient/tests/html_to_md/table1.html @@ -0,0 +1,12 @@ + + + + +
+
$ sudo ethtool --set-priv-flags p2p1 mlx4_rss_xor_hash_function on
+
# Three empty lines follow
+

+

+
+ +Some text \ No newline at end of file diff --git a/CliClient/tests/html_to_md/table1.md b/CliClient/tests/html_to_md/table1.md new file mode 100644 index 0000000000..84b87b4b70 --- /dev/null +++ b/CliClient/tests/html_to_md/table1.md @@ -0,0 +1,5 @@ +| | +| --- | +| $ sudo ethtool --set-priv-flags p2p1 mlx4_rss_xor_hash_function on
# Three empty lines follow
| + +Some text \ No newline at end of file diff --git a/ReactNativeClient/lib/import-enex-md-gen.js b/ReactNativeClient/lib/import-enex-md-gen.js index a21c6ccc7d..3a0bdc3f30 100644 --- a/ReactNativeClient/lib/import-enex-md-gen.js +++ b/ReactNativeClient/lib/import-enex-md-gen.js @@ -377,7 +377,7 @@ function processMdArrayNewLines(md, isTable = false) { // on various rules. const isHeading = function(line) { - return !!line.match(/#+\s/); + return !!line.match(/^#+\s/); } const isListItem = function(line) { @@ -389,7 +389,7 @@ function processMdArrayNewLines(md, isTable = false) { } const isTableLine = function(line) { - return line.indexOf('|') === 0; + return line.indexOf('| ') === 0; } const isPlainParagraph = function(line) { @@ -433,6 +433,12 @@ function formatMdLayout(lines) { } else if (!isCodeLine(line) && isCodeLine(previous)) { newLines.push(''); + + } else if (isTableLine(line) && !isTableLine(previous)) { + newLines.push(''); + + } else if (!isTableLine(line) && isTableLine(previous)) { + newLines.push(''); // Add a new line at beginning of paragraph } else if (isPlainParagraph(line) && previous) {