-
Notifications
You must be signed in to change notification settings - Fork 7
Fix stacked modals on Mermaid diagrams and squished figure captions #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+121
−2
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
36fa6fd
Fix stacked modals on Mermaid diagrams and squished figure captions
JakeSCahill ad9fde5
Add vertical space between Mermaid subgraph labels and nested subgraphs
JakeSCahill a7f9a7c
Address review: hidden-tab retry and top-level-only viewBox growth
JakeSCahill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| ;(function () { | ||
| 'use strict' | ||
|
|
||
| // Mermaid (v10 and v11) never reserves vertical space between a subgraph | ||
| // label and nested subgraphs: the label overlaps the inner boxes' top | ||
| // borders, and neither flowchart.subGraphTitleMargin nor flowchart.padding | ||
| // moves the children. Fix the rendered SVG instead: shift the label up and | ||
| // grow the cluster rect (and the viewBox for top-level clusters) to match. | ||
|
|
||
| const MIN_GAP = 12 | ||
|
|
||
| if (!document.querySelector('.mermaid')) return | ||
|
|
||
| function fixSvg (svg) { | ||
| // Hidden diagrams (e.g. in an inactive context-switcher tab) have no | ||
| // layout: getBBox() throws in Firefox and returns zero-height boxes in | ||
| // Chrome. Leave them unstamped so a later pass can fix them once revealed. | ||
| if (svg.getClientRects().length === 0) return | ||
|
|
||
| const clusters = Array.from(svg.querySelectorAll('g.cluster')) | ||
|
|
||
| function contains (outer, inner) { | ||
| const ox = parseFloat(outer.getAttribute('x')) | ||
| const oy = parseFloat(outer.getAttribute('y')) | ||
| const ow = parseFloat(outer.getAttribute('width')) | ||
| const oh = parseFloat(outer.getAttribute('height')) | ||
| const ix = parseFloat(inner.getAttribute('x')) | ||
| const iy = parseFloat(inner.getAttribute('y')) | ||
| const iw = parseFloat(inner.getAttribute('width')) | ||
| const ih = parseFloat(inner.getAttribute('height')) | ||
| return ix >= ox - 1 && ix + iw <= ox + ow + 1 && iy > oy && iy + ih <= oy + oh + 1 | ||
| } | ||
|
|
||
| // Clusters are processed in document order and measured live, so a | ||
| // cluster shifted early feeds its new position to clusters measured | ||
| // later. The one-directional (upward) shifts keep that stable enough | ||
| // in practice; don't rely on exact pixel positions across siblings. | ||
| let viewBoxGrow = 0 | ||
| clusters.forEach(function (cluster) { | ||
| const rect = cluster.querySelector('rect') | ||
| const label = cluster.querySelector('.cluster-label') | ||
| if (!rect || !label) return | ||
| const ry = parseFloat(rect.getAttribute('y')) | ||
| const rh = parseFloat(rect.getAttribute('height')) | ||
| const m = (label.getAttribute('transform') || '').match(/translate\(\s*([-\d.]+)[ ,]\s*([-\d.]+)\s*\)/) | ||
| if (!m) return | ||
| const lx = parseFloat(m[1]) | ||
| const ly = parseFloat(m[2]) | ||
| let lh | ||
| try { | ||
| lh = label.getBBox().height | ||
| } catch (e) { | ||
| return // not rendered (display: none); leave untouched | ||
| } | ||
| // Find the highest cluster rect fully contained in this one | ||
| let minChildTop = Infinity | ||
| clusters.forEach(function (other) { | ||
| if (other === cluster) return | ||
| const or = other.querySelector('rect') | ||
| if (!or) return | ||
| const oy = parseFloat(or.getAttribute('y')) | ||
| if (contains(rect, or) && oy < minChildTop) minChildTop = oy | ||
| }) | ||
| if (minChildTop === Infinity) return | ||
| const gap = minChildTop - (ly + lh) | ||
| if (gap >= MIN_GAP) return | ||
| const delta = Math.ceil(MIN_GAP - gap) | ||
| // Only top-level clusters push against the viewBox; a shift on a | ||
| // nested cluster is absorbed inside its parent. Decide before the | ||
| // shift moves this rect relative to its parent. | ||
| const isNested = clusters.some(function (other) { | ||
| if (other === cluster) return false | ||
| const or = other.querySelector('rect') | ||
| return or && contains(or, rect) | ||
| }) | ||
| label.setAttribute('transform', 'translate(' + lx + ', ' + (ly - delta) + ')') | ||
| rect.setAttribute('y', ry - delta) | ||
| rect.setAttribute('height', rh + delta) | ||
| if (!isNested) viewBoxGrow = Math.max(viewBoxGrow, delta) | ||
| }) | ||
| if (viewBoxGrow > 0) { | ||
| const vb = (svg.getAttribute('viewBox') || '').split(/[ ,]+/).map(Number) | ||
| if (vb.length === 4 && vb.every(function (n) { return !isNaN(n) })) { | ||
| vb[1] -= viewBoxGrow | ||
| vb[3] += viewBoxGrow | ||
| svg.setAttribute('viewBox', vb.join(' ')) | ||
| } | ||
| } | ||
| svg.setAttribute('data-label-spacing', 'fixed') | ||
| } | ||
|
|
||
| function fixPending () { | ||
| document.querySelectorAll('.mermaid svg:not([data-label-spacing])').forEach(fixSvg) | ||
| } | ||
|
|
||
| // Mermaid renders asynchronously after its module loads; poll briefly. | ||
| let attempts = 0 | ||
| const timer = setInterval(function () { | ||
| attempts++ | ||
| fixPending() | ||
| const remaining = document.querySelectorAll('.mermaid:not([data-processed])').length | ||
| if (remaining === 0 || attempts > 100) { | ||
| clearInterval(timer) | ||
| // Diagrams hidden while the poll ran (e.g. in inactive tabs) are left | ||
| // unstamped; retry after clicks, which is how tabs get revealed. The | ||
| // selector is empty once everything is fixed, so this stays cheap. | ||
| if (document.querySelector('.mermaid svg:not([data-label-spacing])')) { | ||
| document.addEventListener('click', function () { setTimeout(fixPending, 50) }) | ||
| } | ||
| } | ||
| }, 200) | ||
| })() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,4 @@ | |
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="modal-overlay" id="modal-overlay"></div> | ||
| </form> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: redpanda-data/docs-ui
Length of output: 20505
🌐 Web query:
Antora asciidoctor asciimath mermaid block imageblock generated HTML .mermaid .content .title💡 Result:
In Antora, Mermaid diagrams are not supported out-of-the-box by Asciidoctor and require specific extensions [1][2][3]. There are two primary ways to handle them: via the
@sntke/antora-mermaid-extension(client-side rendering) or via extensions like asciidoctor-kroki (server-side rendering) [1][4]. Client-side rendering with@sntke/antora-mermaid-extension: This extension preserves the Mermaid source in the generated HTML [1][5]. When a [mermaid] block is processed, it typically outputs a block element (often a div or pre) assigned the CSS class.mermaid [5]. The structure of the generated HTML generally includes:.mermaid: The container element for the diagram [5]..content: Within the container, the raw text definition of the Mermaid diagram is preserved [5]..title: If a title is provided for the block in AsciiDoc (e.g.,.Diagram Title), it is rendered by Asciidoctor and typically appears as a separate element (e.g.,.title) associated with the block [5]. Configuration: To use this, you must add the extension to your antora-playbook.yaml under the antora.extensions section, not the asciidoc.extensions section [1][6]. You will also need to ensure the Mermaid.js library is loaded via your UI bundle's scripts [1][7]. Server-side rendering with Kroki: Alternatively, using asciidoctor-kroki allows for rendering diagrams into image files (e.g., SVG or PNG) at build time [8][4]. In this approach, the output is typically a standard AsciiDoc block image [9]. This is configured by adding asciidoctor-kroki to the asciidoc.extensions list in your playbook [4]. Important Note: If you are using the@sntke/antora-mermaid-extension, be aware that misconfiguration of attributes in your antora.yml can sometimes interfere with block processing [5]. Always ensure you are targeting the correct extension facility (Antora vs. Asciidoctor) based on your chosen rendering method [6].Citations:
Target the direct children when matching Mermaid titles.
The current selector depends on
.titlebeing the immediate sibling of.mermaid; if the rendered block contains a sibling child wrapper before the title, the spacing rule won’t apply. Use a more direct structural selector, such as.doc .imageblock .mermaid + .title, to reduce reliance on sibling ordering without losing the intended target.🤖 Prompt for AI Agents