Skip to content

Instantly share code, notes, and snippets.

@patrickarlt
Created June 14, 2019 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickarlt/2ee1f4ba753a4c3c084d74a7728ab157 to your computer and use it in GitHub Desktop.
Save patrickarlt/2ee1f4ba753a4c3c084d74a7728ab157 to your computer and use it in GitHub Desktop.
var unified = require("unified");
var remarkParse = require("remark-parse");
var remarkStringify = require("remark-stringify");
var { matches } = require("unist-util-select");
var remove = require("unist-util-remove");
var markdown = `
# Test
# No Really
## Test
Foo
`;
function plugin(options) {
return function transformer(tree, file) {
remove(tree, function(node) {
return matches(`heading[depth=1]`, node);
});
};
}
unified()
.use(remarkParse)
.use(plugin)
.use(remarkStringify)
.process(markdown)
.then(file => console.log(file.contents));
/*
## Test
Foo
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment