-
Notifications
You must be signed in to change notification settings - Fork 3
fix(theme): add remark plugin to tag wide table columns #238
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
Open
jp-ayyappan
wants to merge
7
commits into
main
Choose a base branch
from
fix/table-display
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
73c37e8
feat(tables): add remark plugin to tag wide table columns
jp-ayyappan 286ef66
Update plugins/remark-table-wide-cells.js
jp-ayyappan 3c016fd
Update plugins/remark-table-wide-cells.js
jp-ayyappan cedabd8
Merge branch 'main' into fix/table-display
jp-ayyappan f3b0c33
Merge branch 'main' into fix/table-display
jp-ayyappan 2f7cd8d
fix(theme): align remark-table-wide-cells with DSP implementation
jp-ayyappan f4d1a43
Merge branch 'main' into fix/table-display
jp-ayyappan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * 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]; | ||
| 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 || {}; | ||
| let existing = cell.data.hProperties.className || []; | ||
| if (typeof existing === 'string') existing = [existing]; | ||
| cell.data.hProperties.className = Array.from(new Set([...existing, 'wide-cell'])); | ||
| } | ||
| } | ||
| }); | ||
| }; | ||
| } | ||
|
|
||
| module.exports = remarkTableWideCells; | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.