From 0019bd147a36107468cf44afb0044605de82fd00 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 23 Jun 2021 11:55:10 +0100 Subject: [PATCH] Desktop, Cli: Fixes #4965: Handle special type of code block when importing ENEX files --- packages/app-cli/tests/enex_to_md/code5.html | 1 + packages/app-cli/tests/enex_to_md/code5.md | 13 +++++++++++ packages/lib/import-enex-md-gen.ts | 24 ++++---------------- 3 files changed, 18 insertions(+), 20 deletions(-) create mode 100644 packages/app-cli/tests/enex_to_md/code5.html create mode 100644 packages/app-cli/tests/enex_to_md/code5.md diff --git a/packages/app-cli/tests/enex_to_md/code5.html b/packages/app-cli/tests/enex_to_md/code5.html new file mode 100644 index 0000000000..3d6d0f5d60 --- /dev/null +++ b/packages/app-cli/tests/enex_to_md/code5.html @@ -0,0 +1 @@ +

public class SwapIntegerWithoutTemp {

    public void swapAddition() {
        int a = 3;
        int b = 5;

        a = a + b; // a=8, b=5
        b = a - b; // a=8, b=3
        a = a - b; // a=5, b=3
    }
}

\ No newline at end of file diff --git a/packages/app-cli/tests/enex_to_md/code5.md b/packages/app-cli/tests/enex_to_md/code5.md new file mode 100644 index 0000000000..a5dbcb99ae --- /dev/null +++ b/packages/app-cli/tests/enex_to_md/code5.md @@ -0,0 +1,13 @@ +``` +public class SwapIntegerWithoutTemp { + +    public void swapAddition() { +        int a = 3; +        int b = 5; + +        a = a + b; // a=8, b=5 +        b = a - b; // a=8, b=3 +        a = a - b; // a=5, b=3 +    } +} +``` \ No newline at end of file diff --git a/packages/lib/import-enex-md-gen.ts b/packages/lib/import-enex-md-gen.ts index 78d1098b52..49bddf2c6d 100644 --- a/packages/lib/import-enex-md-gen.ts +++ b/packages/lib/import-enex-md-gen.ts @@ -503,31 +503,15 @@ function isCodeBlock(context: any, nodeName: string, attributes: any) { if (nodeName === 'code') return true; if (attributes && attributes.style) { - const enCodeBlock = cssValue(context, attributes.style, '-en-codeblock'); + // Yes, this property sometimes appears as -en-codeblock, sometimes as + // --en-codeblock. Would be too easy to import ENEX data otherwise. + // https://github.com/laurent22/joplin/issues/4965 + const enCodeBlock = cssValue(context, attributes.style, '-en-codeblock') || cssValue(context, attributes.style, '--en-codeblock'); if (enCodeBlock && enCodeBlock.toLowerCase() === 'true') return true; } return false; } -// function removeSectionParent(section:Section | string) { -// if (typeof section === 'string') return section; - -// section = { ...section }; -// delete section.parent; - -// section.lines = section.lines.slice(); - -// for (let i = 0; i < section.lines.length; i++) { -// section.lines[i] = removeSectionParent(section.lines[i]); -// } - -// return section; -// } - -// function printSection(section:Section) { -// console.info(JSON.stringify(removeSectionParent(section), null, 4)); -// } - function enexXmlToMdArray(stream: any, resources: ResourceEntity[]): Promise { const remainingResources = resources.slice();