mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
Co-authored-by: Dan Abramov <dan.abramov@me.com> Co-authored-by: Sylwia Vargas <sylwia.vargas@gmail.com> Co-authored-by: Dan Lebowitz <dan.lebo@me.com> Co-authored-by: Razvan Gradinar <grazvan@fb.com> Co-authored-by: Jared Palmer <jared@palmer.net> Co-authored-by: Dane Grant <danecando@gmail.com> Co-authored-by: Dustin Goodman <dustin.s.goodman@gmail.com> Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com> Co-authored-by: Maggie Appleton <maggie.fm.appleton@gmail.com> Co-authored-by: Alex Moldovan <alex.n.moldovan@gmail.com> Co-authored-by: Ives van Hoorne <ives.v.h@gmail.com> Co-authored-by: Brian Vaughn <bvaughn@fb.com> Co-authored-by: Dmitri Pavlutin <dpavlutin@gmail.com>
22 lines
565 B
JavaScript
22 lines
565 B
JavaScript
const visit = require('unist-util-visit');
|
|
const retext = require('retext');
|
|
const smartypants = require('retext-smartypants');
|
|
|
|
function check(parent) {
|
|
if (parent.tagName === 'script') return false;
|
|
if (parent.tagName === 'style') return false;
|
|
return true;
|
|
}
|
|
|
|
module.exports = function (options) {
|
|
const processor = retext().use(smartypants, options);
|
|
|
|
function transformer(tree) {
|
|
visit(tree, 'text', (node, index, parent) => {
|
|
if (check(parent)) node.value = String(processor.processSync(node.value));
|
|
});
|
|
}
|
|
|
|
return transformer;
|
|
};
|