-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
feat: create css-only responsive table #8098
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
base: main
Are you sure you want to change the base?
Changes from all commits
73af326
109cf27
dae9a24
d24d86a
691a5ff
f041b36
9deb3a7
7a468fb
d9f70ff
c746449
c143f08
94c6961
5d70b8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Shameless plug here, disclaimer: I wrote this package, so no need to use it if you don't want) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a good idea. Your implementation already has tests, etc., but let's see what the rest of the team thinks first There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for this package |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { Root } from 'mdast'; | ||
import { toString } from 'mdast-util-to-string'; | ||
import { visit } from 'unist-util-visit'; | ||
|
||
/** | ||
* Remark plugin that adds data-label attributes to table cells (td) | ||
* based on their corresponding table headers (th). | ||
*/ | ||
export default function remarkTableTitles() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent approach! |
||
return (tree: Root) => { | ||
visit(tree, 'table', table => { | ||
// Ensure table has at least a header row and one data row | ||
if (table.children.length < 2) return; | ||
|
||
const [headerRow, ...dataRows] = table.children; | ||
|
||
if (headerRow.children.length <= 1) { | ||
table.data ??= {}; | ||
|
||
table.data.hProperties = { | ||
'data-cards': 'false', | ||
}; | ||
} | ||
|
||
// Extract header labels from the first row | ||
const headerLabels = headerRow.children.map(headerCell => | ||
toString(headerCell.children) | ||
); | ||
|
||
// Assign data-label to each cell in data rows | ||
dataRows.forEach(row => { | ||
row.children.forEach((cell, idx) => { | ||
cell.data ??= {}; | ||
|
||
if (idx > headerLabels.length) { | ||
return; | ||
} | ||
|
||
cell.data.hProperties = { | ||
'data-label': headerLabels[idx], | ||
}; | ||
araujogui marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); | ||
}); | ||
}; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.