@nlux/highlighter
Version:
Syntax highlighter for nlux
2 lines (1 loc) • 1.11 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("highlight.js/lib/common")):"function"==typeof define&&define.amd?define(["exports","highlight.js/lib/common"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@nlux/highlighter"]={},t.hljs)}(this,(function(t,e){"use strict";const i={js:"javascript",ts:"typescript",jsx:"javascript",tsx:"typescript",html:"xml",html5:"xml",md:"markdown",yml:"yaml",py:"python",rb:"ruby",kt:"kotlin",rs:"rust"},n=(()=>{const t="dark";let n=t;for(const[t,n]of Object.entries(i))e.getLanguage(n)?e.registerAliases(t,{languageName:n}):"string"!=typeof(l=`Language "${n}" is not registered to use with highlight.js.`)?l&&"function"==typeof l.toString?console.warn(`[nlux] ${l.toString()}`):console.warn("[nlux]"):console.warn(`[nlux] ${l}`);var l;const o=(t,i)=>{const n=e.getLanguage(i)?i:"plaintext";return e.highlight(t,{language:n,ignoreIllegals:!0}).value};return{createHighlighter(e){const{colorMode:i}=e??{};return(t=>{n=t})(i??t),o},highlightingClass:t=>"light"===n?"highlighter-light":"highlighter-dark"}})();t.highlighter=n}));