From d252a70f97217547e471d5a1dc1ae25f06fea41f Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Fri, 13 Sep 2024 13:40:07 -0700 Subject: [PATCH 1/2] dashboard - create text title div properly --- src/format/dashboard/format-dashboard-card.ts | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/format/dashboard/format-dashboard-card.ts b/src/format/dashboard/format-dashboard-card.ts index 6b1fa21f4d..2a31cea96c 100644 --- a/src/format/dashboard/format-dashboard-card.ts +++ b/src/format/dashboard/format-dashboard-card.ts @@ -40,7 +40,6 @@ const kCardHeaderClass = "card-header"; const kCardFooterClass = "card-footer"; const kCardTitleClass = "card-title"; const kCardToolbarClass = "card-toolbar"; -const kCardTitleToolbarClass = "card-title-toolbar"; const kCardSidebarClass = "card-sidebar"; @@ -152,17 +151,27 @@ export function processCards(doc: Document, dashboardMeta: DashboardMeta) { if (cardHeaderEl) { // Loose text gets grouped into a div for alignment purposes // Always place this element first no matter what else is going on - const looseText: string[] = []; + const looseText: Node[] = []; // See if there is a toolbar in the header const cardToolbarEl = cardHeaderEl.querySelector(`.${kCardToolbarClass}`); - for (const headerChildNode of cardHeaderEl.childNodes) { + const isText = (node: Node) => node.nodeType === Node.TEXT_NODE; + const isEmphasis = (node: Node) => node.nodeName === "EM"; + const isBold = (node: Node) => node.nodeName === "STRONG"; + const isMath = (node: Node) => + node.nodeName === "SPAN" && + (node as Element).classList.contains("math") && + (node as Element).classList.contains("inline"); + + for (const headerChildNode of Array.from(cardHeaderEl.childNodes)) { if ( - headerChildNode.nodeType === Node.TEXT_NODE && - headerChildNode.textContent.trim() !== "" + isText(headerChildNode) || + isEmphasis(headerChildNode) || + isBold(headerChildNode) || + isMath(headerChildNode) ) { - looseText.push(headerChildNode.textContent.trim()); + looseText.push(headerChildNode); headerChildNode.parentNode?.removeChild(headerChildNode); } } @@ -172,7 +181,13 @@ export function processCards(doc: Document, dashboardMeta: DashboardMeta) { const classes = [kCardTitleClass]; const titleTextDiv = makeEl("DIV", { classes }, doc); - titleTextDiv.innerText = looseText.join(" "); + const innerSpan = makeEl("SPAN", { + attributes: { style: "display: inline" }, + }, doc); + titleTextDiv.appendChild(innerSpan); + for (const node of looseText) { + innerSpan.appendChild(node); + } if (cardToolbarEl) { cardToolbarEl.insertBefore(titleTextDiv, cardToolbarEl.firstChild); } else { From 4cda934c8b88e15cfdd878dd826fe19906219ae6 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Fri, 13 Sep 2024 13:42:56 -0700 Subject: [PATCH 2/2] regression test, changelog --- news/changelog-1.6.md | 4 ++++ .../docs/smoke-all/2024/09/13/issue-10340.qmd | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/docs/smoke-all/2024/09/13/issue-10340.qmd diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index 09c4128844..eaf12cc11a 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -12,6 +12,10 @@ All changes included in 1.6: - ([#10328](https://github.com/quarto-dev/quarto-cli/issues/10328)): Interpret subcells as subfloats when subcap count matches subcell count. - ([#10624](https://github.com/quarto-dev/quarto-cli/issues/10624)): Don't crash when proof environments are empty in `pdf`. +## `dashboard` Format + +- ([#10340](https://github.com/quarto-dev/quarto-cli/issues/10340)): Build card title correctly in the presence of equations and other markup. + ## `html` Format - Fix `kbd` element styling on dark themes. diff --git a/tests/docs/smoke-all/2024/09/13/issue-10340.qmd b/tests/docs/smoke-all/2024/09/13/issue-10340.qmd new file mode 100644 index 0000000000..7cd73579c9 --- /dev/null +++ b/tests/docs/smoke-all/2024/09/13/issue-10340.qmd @@ -0,0 +1,20 @@ +--- +title: "Test Dashboard" +format: dashboard +_quarto: + tests: + dashboard: + ensureHtmlElements: + - [] + - + - "div.card-header > span.math.inline" + - "div.card-header > em" + - "div.card-header > strong" +--- + +## +::: {.card title="Math $y=mx+b$ between *emphasized* and **bold** words"} + +Math $y=mx+b$ between words + +::: \ No newline at end of file