Desktop, Cli: Fixed importing certain code blocks from ENEX

Ref: https://discourse.joplinapp.org/t/13113
pull/4215/head
Laurent Cozic 2020-12-19 15:36:53 +00:00
parent 33c5037816
commit f53a7d3a8a
4 changed files with 21 additions and 16 deletions

View File

@ -44,14 +44,18 @@ describe('EnexToMd', function() {
} }
if (actualMd !== expectedMd) { if (actualMd !== expectedMd) {
console.info(''); const result = [];
console.info(`Error converting file: ${htmlFilename}`);
console.info('--------------------------------- Got:'); result.push('');
console.info(actualMd.split('\n')); result.push(`Error converting file: ${htmlFilename}`);
console.info('--------------------------------- Expected:'); result.push('--------------------------------- Got:');
console.info(expectedMd.split('\n')); result.push(actualMd.split('\n').map((l: string) => `"${l}"`).join('\n'));
console.info('--------------------------------------------'); result.push('--------------------------------- Expected:');
console.info(''); result.push(expectedMd.split('\n').map((l: string) => `"${l}"`).join('\n'));
result.push('--------------------------------------------');
result.push('');
console.info(result.join('\n'));
expect(false).toBe(true); expect(false).toBe(true);
// return; // return;

View File

@ -0,0 +1,2 @@
<pre style="font-family: monospace;"><code><div>jq -r <span>'.[]|[.index, .name, .section, .award, .industry]|join("\t")'</span> raw.json |pbcopy
</div></code></pre>

View File

@ -0,0 +1 @@
jq -r '.[]|[.index, .name, .section, .award, .industry]|join("\t")' raw.json |pbcopy

View File

@ -392,10 +392,8 @@ function isSpanStyleBold(attributes) {
if (style.includes('font-weight: bold;')) { if (style.includes('font-weight: bold;')) {
return true; return true;
} else if (style.search(/font-family:.*,Bold.*;/) != -1) { } else if (style.search(/font-family:.*,Bold.*;/) != -1) {
// console.debug('font-family regex matched');
return true; return true;
} else { } else {
// console.debug('Found unsupported style(s) in span tag: %s', style);
return false; return false;
} }
} }
@ -700,14 +698,14 @@ function enexXmlToMdArray(stream, resources) {
} }
} else if (n == 'span') { } else if (n == 'span') {
if (isSpanWithStyle(nodeAttributes)) { if (isSpanWithStyle(nodeAttributes)) {
// console.debug('Found style(s) in span tag: %s', nodeAttributes.style); // Found style(s) in span tag
state.spanAttributes.push(nodeAttributes); state.spanAttributes.push(nodeAttributes);
if (isSpanStyleBold(nodeAttributes)) { if (isSpanStyleBold(nodeAttributes)) {
// console.debug('Applying style found in span tag: bold') // Applying style found in span tag: bold'
section.lines.push('**'); section.lines.push('**');
} }
if (isSpanStyleItalic(nodeAttributes)) { if (isSpanStyleItalic(nodeAttributes)) {
// console.debug('Applying style found in span tag: italic') // Applying style found in span tag: italic'
section.lines.push('*'); section.lines.push('*');
} }
} }
@ -753,7 +751,7 @@ function enexXmlToMdArray(stream, resources) {
state.inCode.pop(); state.inCode.pop();
if (!state.inCode.length) { if (!state.inCode.length) {
const codeLines = section.lines.join('').split('\n'); const codeLines = processMdArrayNewLines(section.lines).split('\n');
section.lines = []; section.lines = [];
if (codeLines.length > 1) { if (codeLines.length > 1) {
for (let i = 0; i < codeLines.length; i++) { for (let i = 0; i < codeLines.length; i++) {
@ -892,11 +890,11 @@ function enexXmlToMdArray(stream, resources) {
const attributes = state.spanAttributes.pop(); const attributes = state.spanAttributes.pop();
if (isSpanWithStyle(attributes)) { if (isSpanWithStyle(attributes)) {
if (isSpanStyleBold(attributes)) { if (isSpanStyleBold(attributes)) {
// console.debug('Applying style found in span tag (closing): bold') // Applying style found in span tag (closing): bold'
section.lines.push('**'); section.lines.push('**');
} }
if (isSpanStyleItalic(attributes)) { if (isSpanStyleItalic(attributes)) {
// console.debug('Applying style found in span tag (closing): italic') // Applying style found in span tag (closing): italic'
section.lines.push('*'); section.lines.push('*');
} }
} }