Last active
September 10, 2020 17:38
-
-
Save sayjeyhi/ed702fdd3dc8fab86066b22a06e28bd0 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 crypto = require("crypto"); | |
module.exports = { | |
onWillParseMarkdown: function (markdown) { | |
return new Promise((resolve, reject) => { | |
return resolve(markdown); | |
}); | |
}, | |
onDidParseMarkdown: function (html, { cheerio }) { | |
return new Promise((resolve, reject) => { | |
const makeUrl = (name) => { | |
return crypto | |
.createHash(algorithm || "md5") | |
.update(name, "utf8") | |
.digest(encoding || "hex"); | |
}; | |
// get heading tags and add link and id on them | |
html = html.replace( | |
/(<h[1-6]>)(.*)(<\/h[1-6]>)/gm, | |
(whole, p1, p2, p3) => | |
`${p1}<a id="${makeUrl(p2)}" class="anchor" href="#${makeUrl( | |
p2 | |
)}">${p2}</a>${p3}` | |
); | |
return resolve(html); | |
}); | |
}, | |
onWillTransformMarkdown: function (markdown) { | |
return new Promise((resolve, reject) => { | |
return resolve(markdown); | |
}); | |
}, | |
onDidTransformMarkdown: function (markdown) { | |
return new Promise((resolve, reject) => { | |
return resolve(markdown); | |
}); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment