mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop, Cli: Fixes #5213: Import highlighted text from ENEX files
This commit is contained in:
parent
b6cf9d1d5a
commit
75cc73cc0c
1
packages/app-cli/tests/enex_to_md/highlight.html
Normal file
1
packages/app-cli/tests/enex_to_md/highlight.html
Normal file
@ -0,0 +1 @@
|
||||
<span style="background-color: rgb(255, 250, 165);-evernote-highlight:true;">I'll highlight some text.</span>
|
1
packages/app-cli/tests/enex_to_md/highlight.md
Normal file
1
packages/app-cli/tests/enex_to_md/highlight.md
Normal file
@ -0,0 +1 @@
|
||||
==I'll highlight some text.==
|
@ -13,7 +13,7 @@ import Resource from './models/Resource';
|
||||
|
||||
const enexSampleBaseDir = `${supportDir}/../enex_to_md`;
|
||||
|
||||
describe('EnexToMd', function() {
|
||||
describe('import-enex-md-gen', function() {
|
||||
|
||||
beforeEach(async (done) => {
|
||||
await setupDatabaseAndSynchronizer(1);
|
||||
@ -31,7 +31,7 @@ describe('EnexToMd', function() {
|
||||
const htmlPath = `${enexSampleBaseDir}/${htmlFilename}`;
|
||||
const mdPath = `${enexSampleBaseDir}/${filename(htmlFilename)}.md`;
|
||||
|
||||
// if (htmlFilename !== 'multiline_inner_text.html') continue;
|
||||
// if (htmlFilename !== 'highlight.html') continue;
|
||||
|
||||
const html = await shim.fsDriver().readFile(htmlPath);
|
||||
let expectedMd = await shim.fsDriver().readFile(mdPath);
|
||||
|
@ -32,6 +32,7 @@ interface ParserStateTag {
|
||||
name: string;
|
||||
visible: boolean;
|
||||
isCodeBlock: boolean;
|
||||
isHighlight: boolean;
|
||||
}
|
||||
|
||||
interface ParserStateList {
|
||||
@ -512,6 +513,17 @@ function isCodeBlock(context: any, nodeName: string, attributes: any) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isHighlight(context: any, _nodeName: string, attributes: any) {
|
||||
if (attributes && attributes.style) {
|
||||
// Evernote uses various inconsistent CSS prefixes: so far I've found
|
||||
// "--en", "-en", "-evernote", so I'm guessing "--evernote" probably
|
||||
// exists too.
|
||||
const enHighlight = cssValue(context, attributes.style, '-evernote-highlight') || cssValue(context, attributes.style, '--evernote-highlight');
|
||||
if (enHighlight && enHighlight.toLowerCase() === 'true') return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise<EnexXmlToMdArrayResult> {
|
||||
const remainingResources = resources.slice();
|
||||
|
||||
@ -588,6 +600,7 @@ function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise<Ene
|
||||
name: n,
|
||||
visible: isVisible,
|
||||
isCodeBlock: isCodeBlock(this, n, nodeAttributes),
|
||||
isHighlight: isHighlight(this, n, nodeAttributes),
|
||||
};
|
||||
|
||||
state.tags.push(tagInfo);
|
||||
@ -667,7 +680,6 @@ function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise<Ene
|
||||
} else if (n == 'caption') {
|
||||
if (section.type != 'table') {
|
||||
displaySaxWarning(this, 'Found a <caption> tag outside of a <table>');
|
||||
// return;
|
||||
}
|
||||
|
||||
const newSection: Section = {
|
||||
@ -687,13 +699,6 @@ function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise<Ene
|
||||
section.lines.push(newSection);
|
||||
section = newSection;
|
||||
} else if (tagInfo.isCodeBlock) {
|
||||
// state.inPre = false;
|
||||
|
||||
// const previousIsPre = state.tags.length ? state.tags[state.tags.length - 1].name === 'pre' : false;
|
||||
// if (previousIsPre) {
|
||||
// section.lines.pop();
|
||||
// }
|
||||
|
||||
state.inCode.push(true);
|
||||
state.currentCode = '';
|
||||
|
||||
@ -727,6 +732,8 @@ function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise<Ene
|
||||
section.lines.push(`${indent + container.counter}. `);
|
||||
container.counter++;
|
||||
}
|
||||
} else if (tagInfo.isHighlight) {
|
||||
section.lines.push('==');
|
||||
} else if (isStrongTag(n)) {
|
||||
section.lines.push('**');
|
||||
} else if (isStrikeTag(n)) {
|
||||
@ -889,6 +896,8 @@ function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise<Ene
|
||||
// End of note
|
||||
} else if (!poppedTag.visible) {
|
||||
if (section && section.parent) section = section.parent;
|
||||
} else if (poppedTag.isHighlight) {
|
||||
section.lines.push('==');
|
||||
} else if (poppedTag.isCodeBlock) {
|
||||
state.inCode.pop();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user