Last active
October 5, 2021 06:05
-
-
Save jmblog/15b0b51228851e17785ac1b69d60fabd to your computer and use it in GitHub Desktop.
rehype plugin to remove all style attributes
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
import { Transformer } from 'unified'; | |
import { Element } from 'hast'; | |
import { visit } from 'unist-util-visit'; | |
export default function rehypeRemoveStyleAttrs(): Transformer { | |
return (tree) => { | |
visit(tree, 'element', (node: Element) => { | |
if (node.properties?.style) { | |
node.properties.style = undefined; | |
} | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage