magicpatch
Version:
Adds IPython / Jupyter magic commands to IJavascript
20 lines (18 loc) • 639 B
JavaScript
function strToMarkdown(str) {
// TODO: use a library like: https://www.npmjs.com/package/html-entities
return str
// replace & with &
.replace(/&/gm, "&")
// preserve spacing at start of string
// TODO: this is kinda ugly, it'd be nice if a unicode character worked here
.replace(/^ +/gm, (match) => `${match.replace(/ /g, " ")}`)
// replace < with <
.replace(/</gm, "<")
// replace > with >
.replace(/>/gm, ">")
// replace newline with HTML <br>
.replace(/\n/g, "<br>\n");
}
module.exports = {
strToMarkdown,
};