Skip to content

Instantly share code, notes, and snippets.

@VLZH
Last active February 23, 2021 11:53
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 VLZH/59e6c9fc843deb09de09bab71c16aab6 to your computer and use it in GitHub Desktop.
Save VLZH/59e6c9fc843deb09de09bab71c16aab6 to your computer and use it in GitHub Desktop.
Yeap
const unified = require("unified");
const TEXT = "Hello %world% %yeap%";
function customParser(){
this.Parser = (doc) => {
console.log("doc", doc)
return {
type: "TEXT_NODE",
data: doc
}
}
}
function customCompiler(){
this.Compiler = (tree) => {
console.log("tree", tree);
return "Hello!";
}
}
const processor = unified()
.use(customParser)
.use((...args) => {
console.log("ARGS!", args);
})
.use(customCompiler);
processor.processSync(TEXT);
const TEXT = "Hello %world% %yeap%";
function customParser(){
this.Parser = (doc) => {
console.log("doc", doc)
return {
type: "TEXT_NODE",
data: doc
}
}
}
function customCompiler(){
this.Compiler = (tree) => {
console.log("tree", tree);
return "Hello!";
}
}
const processor = unified()
.use(customParser)
.use((...args) => {
console.log("ARGS!", args);
})
.use(customCompiler);
processor.processSync(TEXT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment