nehan-highlight
Version:
nehan plugin for code highlighting
114 lines • 2.93 kB
JavaScript
import * as hljs from 'highlight.js';
import { CssStyleSheet } from 'nehan';
;
const defaultArgs = {
selector: "pre>code",
};
export function create(args) {
const options = Object.assign(Object.assign({}, defaultArgs), args);
const selector = options.selector || "pre>code";
return new CssStyleSheet({
[selector]: {
display: "block",
fontSize: "smaller",
fontFamily: "monospace",
lineHeight: "1.6",
whiteSpace: "pre",
"!dynamic": (ctx) => {
const lang = ctx.element.className.replace("lang-", "") || "html";
let markup = ctx.element.$node.innerHTML.replace(/<br>/g, "\n").trim();
if (lang === "latex") {
markup = markup.replace(/&/g, "&");
}
const markup2 = hljs.default.highlightAuto(markup, [lang]);
ctx.element.innerHTML = markup2.value;
return {};
}
},
".hljs-comment": {
color: "#008000"
},
".hljs-quote": {
color: "#008000"
},
".hljs-variable": {
color: "#008000"
},
".hljs-keyword": {
color: "#00f"
},
".hljs-selector-tag": {
color: "#00f"
},
".hljs-built_in": {
color: "#00f"
},
".hljs-name": {
color: "#00f"
},
".hljs-tag": {
color: "#00f"
},
".hljs-string": {
color: "#a31515"
},
".hljs-title": {
color: "#a31515"
},
".hljs-section": {
color: "#a31515"
},
".hljs-attribute": {
color: "#a31515"
},
".hljs-literal": {
color: "#a31515"
},
".hljs-template-tag": {
color: "#a31515"
},
".hljs-template-variable": {
color: "#a31515"
},
".hljs-type": {
color: "#a31515"
},
".hljs-addition": {
color: "#a31515"
},
".hljs-deletion": {
color: "#2b91af"
},
".hljs-selector-attr": {
color: "#2b91af"
},
".hljs-selector-pseudo": {
color: "#2b91af"
},
".hljs-meta": {
color: "#2b91af"
},
".hljs-doctag": {
color: "#808080"
},
".hljs-attr": {
color: "#f00",
},
".hljs-symbol": {
color: "#00b0e8",
},
".hljs-bullet": {
color: "#00b0e8",
},
".hljs-link": {
color: "#00b0e8",
},
".hljs-emphasis": {
fontStyle: "italic",
},
".hljs-strong": {
fontWeight: "bold",
}
});
}
//# sourceMappingURL=index.js.map