Skip to content

Commit

Permalink
Desktop, Cli: enex_to_md: Support italic in span tags (laurent22#1966)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JOJ0 authored and scoroi committed Nov 10, 2019
1 parent e573027 commit ce769b6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CliClient/tests/enex_to_md/text_formatting_span_italic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div><span style="font-style: italic;">singleline italic text with span style font-style: italic;.</span></div><div><br/></div>
<div><span style="font-style: italic;">multiline italic
text with span style font-style: italic;.</span></div><div><br/></div>

<div><span style="font-style: italic;">singleline italic text with span style font-style: italic;</span> next to normal text with leading space.</div><div><br/></div>
<div><span style="font-style: italic;">singleline italic text with span style font-style: italic; and with trailing space </span>next to normal text.</div><div><br/></div>
<div><span style="font-style: italic;">singleline italic text with span style font-style: italic;</span><span style="font-style: italic;"> next to more italic text with span style font-style: italic; and with leading space.</span></div><div><br/></div>
<div><span style="font-style: italic;">singleline italic text with span style font-style: italic; and with trailing space </span><span style="font-style: italic;">next to more italic text with span style font-style: italic;.</span></div>
11 changes: 11 additions & 0 deletions CliClient/tests/enex_to_md/text_formatting_span_italic.md
Original file line number Diff line number Diff line change
@@ -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;.*
15 changes: 15 additions & 0 deletions ReactNativeClient/lib/import-enex-md-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ce769b6

Please sign in to comment.