Auto-convert tables to first col header (#35533)
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user