diff --git a/CliClient/tests/EnexToMd.js b/CliClient/tests/EnexToMd.js index dbeb0fa6b..9174a0a06 100644 --- a/CliClient/tests/EnexToMd.js +++ b/CliClient/tests/EnexToMd.js @@ -35,7 +35,7 @@ describe('EnexToMd', function() { const htmlPath = basePath + '/' + htmlFilename; const mdPath = basePath + '/' + filename(htmlFilename) + '.md'; - // if (htmlFilename !== 'list5.html') continue; + // if (htmlFilename !== 'multiline_inner_text.html') continue; const html = await shim.fsDriver().readFile(htmlPath); let expectedMd = await shim.fsDriver().readFile(mdPath); diff --git a/CliClient/tests/enex_to_md/multiline_inner_text.html b/CliClient/tests/enex_to_md/multiline_inner_text.html new file mode 100644 index 000000000..408eb370d --- /dev/null +++ b/CliClient/tests/enex_to_md/multiline_inner_text.html @@ -0,0 +1,7 @@ +
Sometimes Evernote +wraps lines inside blocks
+
Sometimes it doesn't wrap them
+
But
+careful
+with
+pre tags
\ No newline at end of file diff --git a/CliClient/tests/enex_to_md/multiline_inner_text.md b/CliClient/tests/enex_to_md/multiline_inner_text.md new file mode 100644 index 000000000..1524e0b49 --- /dev/null +++ b/CliClient/tests/enex_to_md/multiline_inner_text.md @@ -0,0 +1,6 @@ +Sometimes Evernote wraps lines inside blocks +Sometimes it doesn't wrap them +But +careful +with +pre tags \ 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 a9f54403b..c01a76fd4 100644 --- a/ReactNativeClient/lib/import-enex-md-gen.js +++ b/ReactNativeClient/lib/import-enex-md-gen.js @@ -430,8 +430,34 @@ function enexXmlToMdArray(stream, resources) { //reject(e); }) + const unwrapInnerText = text => { + const lines = text.split('\n'); + + let output = ''; + + for (let i = 0; i < lines.length; i++) { + const line = lines[i]; + const nextLine = i < lines.length - 1 ? lines[i+1] : ''; + + if (!line) { + output += '\n'; + continue; + } + + if (nextLine) { + output += line + ' '; + } else { + output += line; + } + } + + return output; + } + saxStream.on('text', function(text) { if (['table', 'tr', 'tbody'].indexOf(section.type) >= 0) return; + + text = !state.inPre ? unwrapInnerText(text) : text; section.lines = collapseWhiteSpaceAndAppend(section.lines, state, text); })