Skip to content

neikiri/polyglot-formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

polyglot-formatter

Polyglot Formatter

HTML5 CSS JavaScript PHP JSON
License Version

Multi-Language Code Beautifier
Auto-detects HTML, CSS, JavaScript, PHP & JSON β€” formats instantly in the browser.



Live version: https://neikiri.dev/polyglot-formatter


πŸ“– About

Polyglot Formatter is a browser-based code beautifier that automatically detects the dominant language of your input and formats it with a single click. It supports HTML, CSS, JavaScript, PHP and JSON β€” including nested code blocks like <style> and <script> inside HTML, or mixed PHP/HTML files.

Everything runs client-side β€” no server, no build step, no account required.


✨ Features

  • Auto-detection β€” Automatically identifies HTML, CSS, JavaScript, PHP and JSON
  • Deep formatting β€” Formats nested <style> / <script> blocks inside HTML, and structural PHP logic inside mixed files
  • Configurable indent β€” Choose between 2 or 4 spaces
  • Line wrapping β€” Adjustable wrap length (40–300 characters)
  • Preserve newlines β€” Option to keep existing line breaks in string values
  • Deep mode β€” Optional aggressive formatting of nested string payloads (with safety warnings)
  • Preserve quoted keys β€” Keeps JSON keys quoted as-is
  • Syntax highlighting β€” Output is highlighted with Prism.js (Tomorrow Night theme)
  • CodeMirror editor β€” Input editor with line numbers, bracket matching and auto-close
  • Copy to clipboard β€” One-click copy of the formatted output
  • Responsive layout β€” Panels stack vertically on mobile devices
  • Dark theme β€” Material Darker color scheme throughout
  • Post-format validation β€” Warns about potential issues after formatting

🌐 Supported Languages

Language Detection Formatting Highlighting
HTML <tag>, <!DOCTYPE> js-beautify html Prism markup
CSS Selectors, @ rules js-beautify css Prism css
JavaScript const, let, function… js-beautify js Prism javascript
PHP <?php, <?= Custom PHP formatter Prism php
JSON Valid {…} / […] JSON.parse + pretty-print Prism json

πŸ“¦ Installation

No build step is required. Clone the repo and open index.html in your browser:

git clone https://github.com/neikiri/polyglot-formatter.git
cd polyglot-formatter

Then open index.html in any modern browser. That's it.

All dependencies (CodeMirror, Prism.js, js-beautify) are loaded from CDN β€” no npm install needed.


πŸš€ Usage

  1. Paste or type code into the left Input panel.
  2. The editor auto-detects the language and switches syntax mode.
  3. Adjust options in the toolbar if needed:
    • Indent β€” 2 or 4 spaces
    • Preserve Newlines β€” prevents Deep Mode from adding line breaks inside strings
    • Wrap β€” maximum line length before wrapping
    • Deep mode β€” aggressive formatting of nested strings (use with caution)
    • Preserve quoted keys β€” keeps JSON keys quoted
  4. Click Format.
  5. The formatted result appears in the right Output panel with syntax highlighting.
  6. Click Copy Output to copy the result to your clipboard.

βš™οΈ Configuration

Default formatting options are defined in js/config.js:

const APP_CONFIG = {
  defaults: {
    indentSize: 2,
    preserveNewlines: true,
    wrapLineLength: 120,
    safeMode: true,
    deepMode: false,
    preserveQuotedKeys: true,
    deepStringValues: false
  }
};

All options can be changed at runtime through the UI toolbar.


πŸ“š CDN Dependencies

Library Version Purpose
CodeMirror 5.65.16 Input code editor
Prism.js 1.29.0 Output syntax highlighting
js-beautify 1.15.1 HTML / CSS / JS formatting engine

🀝 Contributing

Pull requests are welcome. See CONTRIBUTING.md for details.


⚠️ Issues & Limitations

This project is still a work in progress and I’m fully aware that the formatter currently contains a number of bugs and edge cases.

Building a reliable multi-language formatter (HTML β†’ CSS β†’ JS β†’ PHP β†’ JSON) is much more complex than I initially expected. It’s very difficult to handle all possible nested combinations without introducing errors, and honestly β€” I underestimated how hard this problem really is.

Because of that, I’d really appreciate your help πŸ™

If you find any bugs, broken formatting, or unexpected behavior, please report them here: πŸ‘‰ https://github.com/neikiri/polyglot-formatter/issues

Every report helps improve the project.


πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

neikiri GitHub: https://github.com/neikiri


πŸ“¬ Contact

πŸ“§ Email: neikiri@neikiri.dev