Commit 765d1c8a97

765d1c8a97bd83f94ae9df50d2c454d7d5e07f89

parent: c0b7589370

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-07-18 12:58 UTC

table wraping fix

Layout: unified · split

docs/.vitepress/theme/Layout.vue +14
@@ -1004,6 +1004,17 @@ function initTitleOnly() {
10041004 })
10051005}
10061006
1007// Wrap bare tables in their own scroll container so they scroll independently of sibling content.
1008function wrapTablesInRoot(root: ParentNode) {
1009 root.querySelectorAll<HTMLTableElement>('table:not(.scrape-table)').forEach(table => {
1010 if (table.parentElement?.classList.contains('table-scroll')) return
1011 const wrapper = document.createElement('div')
1012 wrapper.className = 'table-scroll'
1013 table.replaceWith(wrapper)
1014 wrapper.appendChild(table)
1015 })
1016}
1017
10071018function initCopyButtonsInRoot(root: ParentNode) {
10081019 root.querySelectorAll<HTMLTableElement>('table').forEach(table => {
10091020 const headers = table.querySelectorAll<HTMLTableCellElement>('thead th')
@@ -1084,6 +1095,7 @@ function initCopyButtonsInRoot(root: ParentNode) {
10841095let copyButtonObserver: MutationObserver | null = null
10851096
10861097function setupManualCopyButtons() {
1098 wrapTablesInRoot(document)
10871099 initCopyButtonsInRoot(document)
10881100
10891101 copyButtonObserver?.disconnect()
@@ -1092,11 +1104,13 @@ function setupManualCopyButtons() {
10921104 for (const node of mutation.addedNodes) {
10931105 if (!(node instanceof HTMLElement)) continue
10941106 if (node.classList.contains('plugin-tabs--content')) {
1107 wrapTablesInRoot(node)
10951108 initCopyButtonsInRoot(node)
10961109 if (faviconsEnabled.value) applyFavicons(node)
10971110 } else {
10981111 node.querySelectorAll<HTMLElement>('.plugin-tabs--content').forEach(
10991112 (panel) => {
1113 wrapTablesInRoot(panel)
11001114 initCopyButtonsInRoot(panel)
11011115 if (faviconsEnabled.value) applyFavicons(panel)
11021116 }
docs/.vitepress/theme/styles/style.scss +17
@@ -544,6 +544,23 @@ table tr:nth-child(odd) {
544544 border-color: #3d3d3d;
545545}
546546
547/* width: max-content forces exact column sizing so favicon toggling doesn't shrink the right-side gap. */
548@media (max-width: 767px) {
549 .vp-doc table:not(.scrape-table) {
550 width: max-content;
551 }
552
553 .vp-doc table:not(.scrape-table) th,
554 .vp-doc table:not(.scrape-table) td {
555 white-space: nowrap;
556 }
557
558 /* Scroll container injected by wrapTablesInRoot in Layout.vue, isolated from sibling content. */
559 .table-scroll {
560 overflow-x: auto;
561 }
562}
563
547564.tip.custom-block table tr,
548565.tip.custom-block table td,
549566.tip.custom-block table th {