ligHTMetaL::poliSH
Code in. Highlighted HTML out. No runtime dependencies.
Highlight 49 languages, choose from eleven themes, or convert ANSI-colored text to HTML. Use poliSH on its own in browsers or Node.js, or add it to MeltDown and MaiDEn through a code-block hook.
Try it
Highlighted result
Generated HTML
ANSI art, not an image
The logo below is terminal text. poliSH turns its 24-bit foreground and background colors into HTML.
Download the original ANSI art.
Edit or replace POLISH.ANS, then reload the art. No rebuild needed.
Loading ANSI art…
Quickstart: browser script
Copy the prebuilt CSS and JavaScript beside your page. The standalone build includes the complete language catalog; instances register only what you pass.
<link rel="stylesheet" href="polish.css">
<pre class="code theme-dark"><code id="code"></code></pre>
<script src="polish.js"></script>
<script>
const highlighter = polish.createHighlighter({ languages: polish.allLanguages });
document.getElementById('code').innerHTML =
highlighter.highlight('const answer = 42;', 'js');
</script>
ES modules and selected languages
Use dist/polish.esm.js for the full-catalog module. With a bundler, import the core and just the grammars you need:
import { createHighlighter } from 'lightmetal/src/polish.js';
import javascript from 'lightmetal/src/polish/languages/javascript.js';
const highlighter = createHighlighter({ languages: [javascript] });
const html = highlighter.highlight('const answer = 42;', 'js');
Highlight MeltDown code blocks
const highlighter = polish.createHighlighter({ languages: polish.allLanguages });
const render = markdown => meltDown.parse(markdown, {
highlight: highlighter.highlight
});
const editor = maiden.init({
element: document.getElementById('editor'),
sourceHighlight: highlighter.highlightTokens,
preview: { render }
});
editor.element.querySelector('.lightmarkdown-preview')
.classList.add('polish', 'theme-dark');
Load each library separately. The sourceHighlight hook colors code while you edit. MeltDown owns preview code-block wrappers; poliSH returns their highlighted contents. Themes change with CSS classes, without highlighting again. See the MaiDEn example for the complete workflow.
Focused tools, flexible output
Language aliases such as js, py, and sh work directly. Unlabelled code uses conservative guessing among registered languages; unknown explicit labels stay plain. Set guessLanguage: false to disable guessing.
Use ansi to convert actual terminal escape sequences, or use the token and terminal-output APIs in Node.js. ANSI colors work in standalone output; MaiDEn keeps inline styles filtered. Use a maintained HTML sanitizer for untrusted documents, and keep grammars and scanner callbacks application-controlled.