You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
565 B
21 lines
565 B
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;
|
|
};
|
|
|