Created
March 23, 2020 19:07
-
-
Save josemarluedke/44e649a96da30e9030b5171e81330b38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const visit = require('unist-util-visit'); | |
const escapeHBS = node => { | |
if(!node.value) { | |
return; | |
} | |
if (((/^({{|<[A-Z]|<\/[A-Z])/g)).test(node.value)) { | |
node.type = 'html'; | |
} | |
} | |
const removeParagraphsWithHTML = (ast) => { | |
return (node) => { | |
if (!node.children) { | |
return | |
} | |
if (node.children[0].type === 'html') { | |
let index = ast.children.findIndex((item) => item === node) | |
ast.children.splice(index, 1, ...node.children); | |
} | |
} | |
} | |
module.exports = function() { | |
return ast => { | |
visit(ast, 'text', escapeHBS) | |
visit(ast, 'paragraph', removeParagraphsWithHTML(ast)) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment