pipr.tools
Pipes
Clean Email Strip formatting from pasted email for clean plain text Clean AI Output Clean plain text from ChatGPT or AI output Decode & Format JWT Decode a JWT and pretty-print header and payload Word Frequency Count word frequency in text

syntax-highlight Syntax-highlight code with language detection

</> Web
Input0 chars
Output0 chars

Flags

--lang string default:

Examples

Syntax-highlight a JavaScript function

Usage
"function greet(name) {
  return `Hello, ${name}!`;
}
console..." | syntax-highlight

Highlight a Python code snippet for a tutorial blog post

Usage
"def fibonacci(n):
    a, b = 0, 1
    for _ in range(n):
   ..." | syntax-highlight

Format and highlight a SQL query for presentation slides

Usage
"SELECT name, email
FROM users
WHERE active = true
ORDER BY n..." | syntax-highlight
View source
async (input, opts = {})=>{
                if (!input.trim()) return "";
                try {
                    const hljs = await import('highlight.js/lib/common').then(async (m)=>{
                        await m.__tla;
                        return m;
                    });
                    const lang = opts.lang?.trim();
                    const result = lang ? hljs.default.highlight(input, {
                        language: lang
                    }) : hljs.default.highlightAuto(input);
                    const styleMap = {
                        "hljs-keyword": "color:#ff7b72",
                        "hljs-selector-tag": "color:#ff7b72",
                        "hljs-literal": "color:#ff7b72",
                        "hljs-type": "color:#ff7b72",
                        "hljs-string": "color:#a5d6ff",
                        "hljs-addition": "color:#a5d6ff;background:rgba(63,185,80,0.1)",
                        "hljs-number": "color:#79c0ff",
                        "hljs-comment": "color:#8b949e;font-style:italic",
                        "hljs-quote": "color:#8b949e;font-style:italic",
                        "hljs-title": "color:#d2a8ff;font-weight:600",
                        "hljs-section": "color:#d2a8ff;font-weight:600",
                        "hljs-built_in": "color:#ffa657",
                        "hljs-name": "color:#ffa657",
                        "hljs-attr": "color:#79c0ff",
                        "hljs-attribute": "color:#79c0ff",
                        "hljs-variable": "color:#ffa657",
                        "hljs-template-variable": "color:#ffa657",
                        "hljs-regexp": "color:#a5d6ff",
                        "hljs-deletion": "color:#ffa198;background:rgba(248,81,73,0.1)",
                        "hljs-params": "color:#c9d1d9",
                        "hljs-meta": "color:#8b949e",
                        "hljs-punctuation": "color:#8b949e"
                    };
                    const inlined = result.value.replace(/class="([^"]*)"/g, (_, classes)=>{
                        const hljsClass = classes.split(" ").find((c)=>styleMap[c]);
                        const style = hljsClass && styleMap[hljsClass];
                        return style ? `style="${style}"` : "";
                    });
                    return `<pre><code style="color:#c9d1d9">${inlined}</code></pre>`;
                } catch (e) {
                    return `Error: ${e.message}`;
                }
            }