1
0
mirror of synced 2025-12-21 02:46:50 -05:00

Auto-convert tables to first col header (#35533)

This commit is contained in:
Peter Bengtsson
2023-03-17 08:53:12 -04:00
committed by GitHub
parent a6cdcfd3a7
commit 4c220747ec
7 changed files with 95 additions and 4 deletions

View File

@@ -6,15 +6,15 @@ import { parseSelector } from 'hast-util-parse-selector'
* Attacher
*/
export default (options) => {
options = options || {}
const selector = options.selector || options.select || 'body'
const wrapper = options.wrapper || options.wrap
const rewrite = options.rewrite
/*
* Transformer
*/
return (tree) => {
if (typeof wrapper !== 'string') {
if (wrapper && typeof wrapper !== 'string') {
throw new TypeError('Expected a `string` as wrapper')
}
@@ -25,7 +25,11 @@ export default (options) => {
for (const match of selectAll(selector, tree)) {
visit(tree, match, (node, i, parent) => {
const parsedWrapper = parseSelector(wrapper)
parsedWrapper.children = [node]
if (rewrite) {
parsedWrapper.children = node.children
} else {
parsedWrapper.children = [node]
}
parent.children[i] = parsedWrapper
})
}