2023-02-03 00:46:44 +01:00
|
|
|
const Chroma = require("chroma-highlight");
|
|
|
|
const parseSyntaxArguments = require("./parseSyntaxArguments");
|
2023-02-02 15:36:15 +01:00
|
|
|
|
|
|
|
module.exports = function (options = {}) {
|
2023-02-03 00:46:44 +01:00
|
|
|
return function (str, args) {
|
|
|
|
if (!args) {
|
2023-02-02 15:36:15 +01:00
|
|
|
// empty string means defer to the upstream escaping code built into markdown lib.
|
2023-02-03 00:46:44 +01:00
|
|
|
return str;
|
2023-02-02 15:36:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let html;
|
2023-02-03 00:46:44 +01:00
|
|
|
|
|
|
|
if (args === "text") {
|
2023-02-02 15:36:15 +01:00
|
|
|
html = str;
|
|
|
|
} else {
|
2023-02-03 00:46:44 +01:00
|
|
|
const parsedArgs = parseSyntaxArguments(args, options);
|
2023-02-02 15:36:15 +01:00
|
|
|
|
2023-02-03 00:46:44 +01:00
|
|
|
let opts = `--formatter html --html-only --html-inline-styles ${parsedArgs} `;
|
2023-02-02 15:36:15 +01:00
|
|
|
|
2023-02-03 00:46:44 +01:00
|
|
|
html = Chroma.highlight(str, opts);
|
|
|
|
}
|
2023-02-02 15:36:15 +01:00
|
|
|
|
2023-02-03 00:46:44 +01:00
|
|
|
return html;
|
2023-02-02 15:36:15 +01:00
|
|
|
};
|
|
|
|
};
|