1
0
mirror of synced 2025-12-20 02:19:14 -05:00
Files
docs/lib/render-content/plugins/wrap-in-element.js
Kevin Heis d68dde17d1 Upgrade pipeline with env COMMONMARK=1 npm start to see new, otherwise parse current (#20508)
* 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>
2021-07-29 14:24:26 +00:00

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
})
}
}
}