UNPKG

@nlux/highlighter

Version:

Syntax highlighter for nlux

2 lines (1 loc) 836 B
import t from"highlight.js/lib/common";const e={js:"javascript",ts:"typescript",jsx:"javascript",tsx:"typescript",html:"xml",html5:"xml",md:"markdown",yml:"yaml",py:"python",rb:"ruby",kt:"kotlin",rs:"rust"},r=(()=>{const r="dark";let g=r;for(const[r,g]of Object.entries(e))t.getLanguage(g)?t.registerAliases(r,{languageName:g}):"string"!=typeof(i=`Language "${g}" is not registered to use with highlight.js.`)?i&&"function"==typeof i.toString?console.warn(`[nlux] ${i.toString()}`):console.warn("[nlux]"):console.warn(`[nlux] ${i}`);var i;const n=(e,r)=>{const g=t.getLanguage(r)?r:"plaintext";return t.highlight(e,{language:g,ignoreIllegals:!0}).value};return{createHighlighter(t){const{colorMode:e}=t??{};return(t=>{g=t})(e??r),n},highlightingClass:t=>"light"===g?"highlighter-light":"highlighter-dark"}})();export{r as highlighter};