From 4deeed0d5c0e38513bad304b2784cf8d9cf2dde1 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 9 Nov 2021 18:33:28 +0000 Subject: [PATCH] Desktop, Mobile: Fixes #5687: Fixed issue with parts of HTML notes not being displayed in some cases --- .../app-cli/tests/enex_to_html/quoted-attributes.enex | 3 +++ .../app-cli/tests/enex_to_html/quoted-attributes.html | 3 +++ .../tests/html_to_html/anchor_missing_href.dest.html | 1 + .../tests/html_to_html/anchor_missing_href.src.html | 1 + packages/lib/import-enex-html-gen.test.js | 11 +++++++++-- packages/lib/resourceUtils.js | 2 +- packages/renderer/htmlUtils.ts | 9 +++++++++ 7 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 packages/app-cli/tests/enex_to_html/quoted-attributes.enex create mode 100644 packages/app-cli/tests/enex_to_html/quoted-attributes.html create mode 100644 packages/app-cli/tests/html_to_html/anchor_missing_href.dest.html create mode 100644 packages/app-cli/tests/html_to_html/anchor_missing_href.src.html diff --git a/packages/app-cli/tests/enex_to_html/quoted-attributes.enex b/packages/app-cli/tests/enex_to_html/quoted-attributes.enex new file mode 100644 index 000000000..7be1ad101 --- /dev/null +++ b/packages/app-cli/tests/enex_to_html/quoted-attributes.enex @@ -0,0 +1,3 @@ + +

Association Between mRNA Vaccination and COVID-19 Hospitalization and Disease Severity

+
diff --git a/packages/app-cli/tests/enex_to_html/quoted-attributes.html b/packages/app-cli/tests/enex_to_html/quoted-attributes.html new file mode 100644 index 000000000..2957f4fc5 --- /dev/null +++ b/packages/app-cli/tests/enex_to_html/quoted-attributes.html @@ -0,0 +1,3 @@ + +

Association Between mRNA Vaccination and COVID-19 Hospitalization and Disease Severity

+
\ No newline at end of file diff --git a/packages/app-cli/tests/html_to_html/anchor_missing_href.dest.html b/packages/app-cli/tests/html_to_html/anchor_missing_href.dest.html new file mode 100644 index 000000000..0a4898926 --- /dev/null +++ b/packages/app-cli/tests/html_to_html/anchor_missing_href.dest.html @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/packages/app-cli/tests/html_to_html/anchor_missing_href.src.html b/packages/app-cli/tests/html_to_html/anchor_missing_href.src.html new file mode 100644 index 000000000..da987591c --- /dev/null +++ b/packages/app-cli/tests/html_to_html/anchor_missing_href.src.html @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/packages/lib/import-enex-html-gen.test.js b/packages/lib/import-enex-html-gen.test.js index 348d9df96..93722af11 100644 --- a/packages/lib/import-enex-html-gen.test.js +++ b/packages/lib/import-enex-html-gen.test.js @@ -41,6 +41,11 @@ const beautifyHtml = (html) => { * ``. */ const compareOutputToExpected = (options) => { + options = { + resources: [], + ...options, + }; + const inputFile = fileWithPath(`${options.testName}.enex`); const outputFile = fileWithPath(`${options.testName}.html`); const testTitle = `should convert from Enex to Html: ${options.testName}`; @@ -62,12 +67,10 @@ describe('EnexToHtml', function() { compareOutputToExpected({ testName: 'checklist-list', - resources: [], }); compareOutputToExpected({ testName: 'svg', - resources: [], }); compareOutputToExpected({ @@ -96,6 +99,10 @@ describe('EnexToHtml', function() { }], }); + compareOutputToExpected({ + testName: 'quoted-attributes', + }); + // it('fails when not given a matching resource', (async () => { // // To test the promise-unexpectedly-resolved case, add `audioResource` to the array. // const resources = []; diff --git a/packages/lib/resourceUtils.js b/packages/lib/resourceUtils.js index 51e6cbda3..cab51da61 100644 --- a/packages/lib/resourceUtils.js +++ b/packages/lib/resourceUtils.js @@ -39,7 +39,7 @@ const imageMimeTypes = [ 'image/vnd.xiff', ]; -const escapeQuotes = (str) => str.replace(/"/g, '"'); +const escapeQuotes = (str) => str.replace(/"/g, '"'); const attributesToStr = (attributes) => Object.entries(attributes) diff --git a/packages/renderer/htmlUtils.ts b/packages/renderer/htmlUtils.ts index 9a27fb31d..0e24f21be 100644 --- a/packages/renderer/htmlUtils.ts +++ b/packages/renderer/htmlUtils.ts @@ -192,6 +192,15 @@ class HtmlUtils { } } + // For some reason, entire parts of HTML notes don't show up in + // the viewer when there's an anchor tag without an "href" + // attribute. It doesn't always happen and it seems to depend on + // what else is in the note but in any case adding the "href" + // fixes it. https://github.com/laurent22/joplin/issues/5687 + if (name.toLowerCase() === 'a' && !attrs['href']) { + attrs['href'] = '#'; + } + let attrHtml = this.attributesHtml(attrs); if (attrHtml) attrHtml = ` ${attrHtml}`; const closingSign = this.isSelfClosingTag(name) ? '/>' : '>';