Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ const config: Config = {
routeBasePath: "/",
sidebarPath: "./sidebars.js",
docItemComponent: "@theme/ApiItem", // Derived from docusaurus-theme-openapi
remarkPlugins: [
[require('./plugins/remark-table-wide-cells'), { threshold: 100 }],
],
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
// editUrl:
Expand Down
64 changes: 64 additions & 0 deletions plugins/remark-table-wide-cells.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Remark plugin that detects table columns with long text content
* and tags all cells in those columns with a `wide-cell` CSS class.
*
* This enables targeted CSS word-wrapping on only the columns that need it,
* keeping short columns compact.
*/
const { visit } = require('unist-util-visit');

/** Recursively extract plain text from an MDAST node. */
function extractText(node) {
if (node.type === 'text' || node.type === 'inlineCode') {
return node.value || '';
}
if (node.children) {
return node.children.map(extractText).join('');
}
return '';
}

function remarkTableWideCells({ threshold = 100 } = {}) {
return (tree) => {
visit(tree, 'table', (table) => {
if (!table.children || table.children.length === 0) return;

// Determine the number of columns from the first row
const numCols = table.children[0].children
? table.children[0].children.length
: 0;
if (numCols === 0) return;

// Check each column: does ANY cell exceed the threshold?
const wideColumns = new Set();
for (const row of table.children) {
if (!row.children) continue;
for (let colIdx = 0; colIdx < row.children.length; colIdx++) {
if (wideColumns.has(colIdx)) continue;
const cell = row.children[colIdx];
Comment thread
jp-ayyappan marked this conversation as resolved.
const text = extractText(cell);
if (text.length > threshold) {
wideColumns.add(colIdx);
}
}
}

if (wideColumns.size === 0) return;

// Tag all cells in wide columns
for (const row of table.children) {
if (!row.children) continue;
for (let colIdx = 0; colIdx < row.children.length; colIdx++) {
if (!wideColumns.has(colIdx)) continue;
const cell = row.children[colIdx];
cell.data = cell.data || {};
cell.data.hProperties = cell.data.hProperties || {};
const existing = cell.data.hProperties.className || [];
cell.data.hProperties.className = Array.from(new Set([...existing, 'wide-cell']));
}
}
});
};
}

module.exports = remarkTableWideCells;
20 changes: 20 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,26 @@ html[data-theme='dark'] div[class*="language-shell"] code::before {
text-decoration: underline;
}

/**************
** TABLES — responsive with targeted wrapping
***************/

/* Make tables responsive with horizontal scroll */
.markdown table {
display: block;
max-width: 100%;
overflow-x: auto;
white-space: nowrap;
}

/* Allow word-wrapping in columns tagged as wide by remark-table-wide-cells */
.markdown table td.wide-cell,
.markdown table th.wide-cell {
white-space: normal;
word-break: break-word;
min-width: 200px;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

/**************
** OPENTDF LANDING — DARK DESIGN TOKENS
***************/
Expand Down
Loading