Skip to content

Commit 40cbbdc

Browse files
committed
fix: render heading fold arrows with CSS
1 parent d88e4ee commit 40cbbdc

5 files changed

Lines changed: 25 additions & 38 deletions

File tree

‎changes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Changes
22
## Unreleased
3+
* Render Markdown heading fold arrows with CSS so they do not paste as oversized SVGs into rich-text editors
34
* Refresh PDF Highlight, Draw, and Text box icons when switching themes
45
* Match the PDF viewer's unused space to the active theme, including live theme changes, without recoloring PDF pages
56
* Place PDF Find And Replace beside Outline, before the page-navigation controls

‎src/data/extra/web/css/exportglobalstyles.css‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@
1717
width: 2.5rem;
1818
}
1919

20-
.vx-heading-fold-icon {
21-
height: 1.5rem;
22-
max-height: 100%;
23-
transform-origin: center;
24-
width: 1.5rem;
20+
/* Generated decoration keeps the chevron out of copied HTML content. */
21+
.vx-heading-fold-toggle::after {
22+
border-bottom: 0.125rem solid currentColor;
23+
border-right: 0.125rem solid currentColor;
24+
box-sizing: content-box;
25+
content: '';
26+
height: 0.5rem;
27+
transform: rotate(45deg);
28+
width: 0.5rem;
2529
}
2630

27-
.vx-heading-fold-toggle[aria-expanded="false"] .vx-heading-fold-icon {
28-
transform: rotate(-90deg);
31+
.vx-heading-fold-toggle[aria-expanded="false"]::after {
32+
transform: rotate(-45deg);
2933
}
3034

3135
.vx-heading-fold > h1:hover > .vx-heading-fold-toggle,

‎src/data/extra/web/css/globalstyles.css‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,19 @@ figcaption {
7070
width: 2.5rem;
7171
}
7272

73-
.vx-heading-fold-icon {
74-
height: 1.5rem;
75-
max-height: 100%;
76-
transform-origin: center;
77-
width: 1.5rem;
78-
}
79-
80-
.vx-heading-fold-toggle[aria-expanded="false"] .vx-heading-fold-icon {
81-
transform: rotate(-90deg);
73+
/* Generated decoration keeps the chevron out of copied HTML content. */
74+
.vx-heading-fold-toggle::after {
75+
border-bottom: 0.125rem solid currentColor;
76+
border-right: 0.125rem solid currentColor;
77+
box-sizing: content-box;
78+
content: '';
79+
height: 0.5rem;
80+
transform: rotate(45deg);
81+
width: 0.5rem;
82+
}
83+
84+
.vx-heading-fold-toggle[aria-expanded="false"]::after {
85+
transform: rotate(-45deg);
8286
}
8387

8488
.vx-heading-fold > h1:hover > .vx-heading-fold-toggle,

‎src/data/extra/web/js/nodelinemapper.js‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,6 @@ class HeadingFolding {
7676
button.setAttribute('aria-expanded', 'true');
7777
button.setAttribute('aria-controls', content.id);
7878
button.setAttribute('aria-label', 'Collapse section');
79-
// Reuse the bundled arrow_dropdown.svg chevron geometry inline so the
80-
// control stays theme-colored and self-contained in standalone exports.
81-
let icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
82-
icon.setAttribute('class', 'vx-heading-fold-icon');
83-
icon.setAttribute('viewBox', '0 0 48 48');
84-
icon.setAttribute('aria-hidden', 'true');
85-
icon.setAttribute('focusable', 'false');
86-
let iconPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');
87-
iconPath.setAttribute('d', 'M36 18L24 30L12 18');
88-
iconPath.setAttribute('fill', 'none');
89-
iconPath.setAttribute('stroke', 'currentColor');
90-
iconPath.setAttribute('stroke-width', '4');
91-
iconPath.setAttribute('stroke-linecap', 'round');
92-
iconPath.setAttribute('stroke-linejoin', 'round');
93-
icon.appendChild(iconPath);
94-
button.appendChild(icon);
9579
node.appendChild(button);
9680

9781
stack.push({ level: level, content: content });
@@ -178,7 +162,6 @@ class HeadingFolding {
178162
p_content.hidden = !p_expanded;
179163
p_button.setAttribute('aria-expanded', p_expanded ? 'true' : 'false');
180164
p_button.setAttribute('aria-label', p_expanded ? 'Collapse section' : 'Expand section');
181-
// The CSS rotates the single down-chevron SVG when aria-expanded is false.
182165
}
183166

184167
expandHiddenAncestors(p_node) {

‎tests/widgets/test_markdownviewer_js.cpp‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,11 +1413,6 @@ void TestMarkdownViewerJs::testHeadingFolding_enabledAndDisabledDecoration() {
14131413
"window.__buttonFor(window.__nodes.alpha).getAttribute('aria-label')"))
14141414
.toString(),
14151415
QStringLiteral("Collapse section"));
1416-
QCOMPARE(engine
1417-
.evaluate(QStringLiteral(
1418-
"document.body.querySelectorAll('svg.vx-heading-fold-icon').length"))
1419-
.toInt(),
1420-
7);
14211416

14221417
res = engine.evaluate(QStringLiteral("window.__mapper.setHeadingFoldingEnabled(false);"));
14231418
QVERIFY2(!res.isError(), qPrintable(res.toString()));

0 commit comments

Comments
 (0)