* Update the trim nightmare * Update create-processor.js * Update other packages in the rendering pipeline * A few more updates * Fix tables * Update lint-files.js * Fix copy code blocks * Update render-content.js * remove whitespace from liquid conditionals * We no longer need require eslint rules * Neat, it worked * Revert test change * Update create-processor.js * Without aliases Co-authored-by: Chiedo John <2156688+chiedo@users.noreply.github.com> Co-authored-by: Rachael Sewell <rachmari@github.com>
34 lines
855 B
JavaScript
34 lines
855 B
JavaScript
import { visit } from 'unist-util-visit'
|
|
import { selectAll } from 'hast-util-select'
|
|
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
|
|
|
|
/*
|
|
* Transformer
|
|
*/
|
|
return (tree) => {
|
|
if (typeof wrapper !== 'string') {
|
|
throw new TypeError('Expected a `string` as wrapper')
|
|
}
|
|
|
|
if (typeof selector !== 'string') {
|
|
throw new TypeError('Expected a `string` as selector')
|
|
}
|
|
|
|
for (const match of selectAll(selector, tree)) {
|
|
visit(tree, match, (node, i, parent) => {
|
|
const parsedWrapper = parseSelector(wrapper)
|
|
parsedWrapper.children = [node]
|
|
parent.children[i] = parsedWrapper
|
|
})
|
|
}
|
|
}
|
|
}
|