From f90cc8d67d150547e6a52300eb67e10ca2b43a44 Mon Sep 17 00:00:00 2001
From: J0J0 T <2733783+JOJ0@users.noreply.github.com>
Date: Sat, 12 Oct 2019 00:39:13 +0200
Subject: [PATCH] Desktop, Cli: enex_to_md: Support italic in span tags (#1966)
* Desktop, Cli: enex_to_md: support italic in span tags
* Desktop, Cli: enex_to_md: readd debug message to resolve CI conflict
* Desktop, Cli: enex_to_md: fix CI errors
add spaces to commented out debug messages
* Desktop, Cli: enex_to_md: remove redundant commented out debug message
* Desktop, Cli: enex_to_md: readd redundant commented out debug message
CI wants it in there - maybe remove in another PR
---
.../enex_to_md/text_formatting_span_italic.html | 8 ++++++++
.../enex_to_md/text_formatting_span_italic.md | 11 +++++++++++
ReactNativeClient/lib/import-enex-md-gen.js | 15 +++++++++++++++
3 files changed, 34 insertions(+)
create mode 100644 CliClient/tests/enex_to_md/text_formatting_span_italic.html
create mode 100644 CliClient/tests/enex_to_md/text_formatting_span_italic.md
diff --git a/CliClient/tests/enex_to_md/text_formatting_span_italic.html b/CliClient/tests/enex_to_md/text_formatting_span_italic.html
new file mode 100644
index 0000000000..85b0428978
--- /dev/null
+++ b/CliClient/tests/enex_to_md/text_formatting_span_italic.html
@@ -0,0 +1,8 @@
+
singleline italic text with span style font-style: italic;.
+multiline italic
+ text with span style font-style: italic;.
+
+singleline italic text with span style font-style: italic; next to normal text with leading space.
+singleline italic text with span style font-style: italic; and with trailing space next to normal text.
+singleline italic text with span style font-style: italic; next to more italic text with span style font-style: italic; and with leading space.
+singleline italic text with span style font-style: italic; and with trailing space next to more italic text with span style font-style: italic;.
diff --git a/CliClient/tests/enex_to_md/text_formatting_span_italic.md b/CliClient/tests/enex_to_md/text_formatting_span_italic.md
new file mode 100644
index 0000000000..c3b1d38bde
--- /dev/null
+++ b/CliClient/tests/enex_to_md/text_formatting_span_italic.md
@@ -0,0 +1,11 @@
+*singleline italic text with span style font-style: italic;.*
+
+*multiline italic text with span style font-style: italic;.*
+
+*singleline italic text with span style font-style: italic;* next to normal text with leading space.
+
+*singleline italic text with span style font-style: italic; and with trailing space *next to normal text.
+
+*singleline italic text with span style font-style: italic;** next to more italic text with span style font-style: italic; and with leading space.*
+
+*singleline italic text with span style font-style: italic; and with trailing space **next to more italic text with span style font-style: italic;.*
\ 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 7dad191c56..9250ae78c4 100644
--- a/ReactNativeClient/lib/import-enex-md-gen.js
+++ b/ReactNativeClient/lib/import-enex-md-gen.js
@@ -400,6 +400,12 @@ function isSpanStyleBold(attributes) {
}
}
+function isSpanStyleItalic(attributes) {
+ let style = attributes.style;
+ style = style.replace(/\s+/g, '');
+ return (style.toLowerCase().includes('font-style:italic;'));
+}
+
function enexXmlToMdArray(stream, resources) {
let remainingResources = resources.slice();
@@ -694,11 +700,16 @@ function enexXmlToMdArray(stream, resources) {
}
} else if (n == 'span') {
if (isSpanWithStyle(nodeAttributes)) {
+ // console.debug('Found style(s) in span tag: %s', nodeAttributes.style);
state.spanAttributes.push(nodeAttributes);
if (isSpanStyleBold(nodeAttributes)) {
// console.debug('Applying style found in span tag: bold')
section.lines.push('**');
}
+ if (isSpanStyleItalic(nodeAttributes)) {
+ // console.debug('Applying style found in span tag: italic')
+ section.lines.push('*');
+ }
}
} else if (['font', 'sup', 'cite', 'abbr', 'small', 'tt', 'sub', 'colgroup', 'col', 'ins', 'caption', 'var', 'map', 'area'].indexOf(n) >= 0) {
// Inline tags that can be ignored in Markdown
@@ -887,6 +898,10 @@ function enexXmlToMdArray(stream, resources) {
// console.debug('Applying style found in span tag (closing): bold')
section.lines.push('**');
}
+ if (isSpanStyleItalic(attributes)) {
+ // console.debug('Applying style found in span tag (closing): italic')
+ section.lines.push('*');
+ }
}
} else if (isIgnoredEndTag(n)) {
// Skip