A platform for community discussion. Free, open, simple.
UX: prevent nested footnotes (#41325)
chapoiea6ffc4852d0
diff --git a/plugins/footnote/assets/javascripts/api-initializers/inline-footnotes.gjs b/plugins/footnote/assets/javascripts/api-initializers/inline-footnotes.gjsindex cf4a42ca03c..380f758d04d 100644--- a/plugins/footnote/assets/javascripts/api-initializers/inline-footnotes.gjs+++ b/plugins/footnote/assets/javascripts/api-initializers/inline-footnotes.gjs@@ -53,7 +53,13 @@ export default apiInitializer((api) => {}const footnoteId = refLink.getAttribute("href");- const footnoteContent = elem.querySelector(footnoteId)?.innerHTML;+ const footnoteElement = elem.querySelector(footnoteId)?.cloneNode(true);++ footnoteElement+ ?.querySelectorAll("sup.footnote-ref, .footnote-backref")+ .forEach((element) => element.remove());++ const footnoteContent = footnoteElement?.innerHTML;const expandableFootnote = document.createElement("span");expandableFootnote.className = "inline-footnote";diff --git a/plugins/footnote/assets/stylesheets/footnotes.scss b/plugins/footnote/assets/stylesheets/footnotes.scssindex 7f941e4329d..026b0e6ecd9 100644--- a/plugins/footnote/assets/stylesheets/footnotes.scss+++ b/plugins/footnote/assets/stylesheets/footnotes.scss@@ -47,10 +47,6 @@flex-direction: column;}- .footnote-backref {- display: none;- }-img {object-fit: cover;max-width: 100%;diff --git a/plugins/footnote/test/javascripts/acceptance/footnote-test.js b/plugins/footnote/test/javascripts/acceptance/footnote-test.jsindex 70e5aac5788..9d0f4f3c514 100644--- a/plugins/footnote/test/javascripts/acceptance/footnote-test.js+++ b/plugins/footnote/test/javascripts/acceptance/footnote-test.js@@ -19,6 +19,7 @@ acceptance("Discourse Footnote Plugin", function (needs) {<p>Lorem ipsum dolor sit amet<sup class="footnote-ref"><a href="#footnote-17-1" id="footnote-ref-17-1">[1]</a></sup></p><p class="second">Second reference should also work. <sup class="footnote-ref"><a href="#footnote-17-1" id="footnote-ref-17-0">[1]</a></sup></p><p class="other">Other page should close<sup class="footnote-ref"><a href="#footnote-17-2" id="footnote-ref-17-2">[2]</a></sup></p>+ <p class="nested">Nested footnote<sup class="footnote-ref"><a href="#footnote-17-3" id="footnote-ref-17-3">[3]</a></sup></p><hr class="footnotes-sep"><ol class="footnotes-list"><li id="footnote-17-1" class="footnote-item">@@ -27,6 +28,9 @@ acceptance("Discourse Footnote Plugin", function (needs) {<li id="footnote-17-2" class="footnote-item"><p><a class="link-in-tooltip" href="/">Index ↩︎</a></p></li>+ <li id="footnote-17-3" class="footnote-item">+ <p>Nested content <sup class="footnote-ref"><a href="#footnote-17-4" id="footnote-ref-17-4">[4]</a></sup> <a href="#footnote-ref-17-3" class="footnote-backref">↩︎</a></p>+ </li></ol>`;return helper.response(topic);@@ -39,7 +43,7 @@ acceptance("Discourse Footnote Plugin", function (needs) {// openawait click(".expand-footnote");- assert.dom(TOOLTIP_SELECTOR).hasText("consectetur adipiscing elit ↩︎");+ assert.dom(TOOLTIP_SELECTOR).hasText("consectetur adipiscing elit");// close by clicking outsideawait triggerEvent(".d-header", "pointerdown");@@ -47,14 +51,14 @@ acceptance("Discourse Footnote Plugin", function (needs) {// open againawait click(".expand-footnote");- assert.dom(TOOLTIP_SELECTOR).hasText("consectetur adipiscing elit ↩︎");+ assert.dom(TOOLTIP_SELECTOR).hasText("consectetur adipiscing elit");});test("clicking a second footnote with same name works", async function (assert) {await visit("/t/-/45");await click(".second .expand-footnote");- assert.dom(TOOLTIP_SELECTOR).hasText("consectetur adipiscing elit ↩︎");+ assert.dom(TOOLTIP_SELECTOR).hasText("consectetur adipiscing elit");});test("closes tooltip when clicking link within tooltip content", async function (assert) {@@ -67,4 +71,16 @@ acceptance("Discourse Footnote Plugin", function (needs) {await click(".link-in-tooltip");assert.dom(TOOLTIP_SELECTOR).doesNotExist();});++ test("removes nested footnotes", async function (assert) {+ await visit("/t/-/45");++ await click(".nested .expand-footnote");++ // the nested footnote does not work, so we strip them out completely+ assert+ .dom(`${TOOLTIP_SELECTOR} sup.footnote-ref`)+ .doesNotExist("removes the nested footnote-ref");+ assert.dom(TOOLTIP_SELECTOR).hasText("Nested content");+ });});