Menu Search
Jump to the content X X
Smashing Conf New York

We use ad-blockers as well, you know. We gotta keep those servers running though. Did you know that we publish useful books and run friendly conferences — crafted for pros like yourself? E.g. upcoming SmashingConf Barcelona, dedicated to smart front-end techniques and design patterns.

Time-Savers: Code Beautifier And Formatter

Well-documented and readable source code is essential for every collaborative project. Logically structured, well organized and nicely formatted, the code can speed up the bug hunting and help to keep the code clean, minimal and still functional. These aspects are particularly important if the code is being developed by a group of developers: in this context a common scheme for source code presentation is necessary. You don’t have to do everything by hand; in fact, there are many tools which can save a lot of time – for you and your co-workers.

The tools and services we’ve collected below aren’t validators. They format and beautify the code; some of them can remove redundant elements. Using them, you have to make sure you have a backup, so your data can always be restored.

Let’s take a look at code beautifier and formatter which can save you a lot of time and help to maintain a clean and readable source code.

Code Beautifier And Formatter Link

  1. Quick Highlighter1
  2. Quick Highlighter can format source codes written in over 85 languages – among them C++, PHP, Ruby, HTML, JavaScript, Perl, Python, Smarty, XML and more. The tool formats source code and highlights inbuilt keywords, data types etc.

    Screenshot2

  3. PrettyPrinter3
  4. Knows PHP, Java, C++, C, Perl, JavaScript, CSS. The service offers many formatting options you can use to present the code just the way you’d like it to look like.

    Screenshot4

  5. PHP Code Beautifier
  6. This tool is designed to beautify PHP code, applying most of the PEAR standard requirements to it. It can even process really scrambled scripts, e.g. all code in one line, and thus may help you to get scripts into a more readable form. It sets missing line breaks without removing any additional line breaks that you may use to group related things and corrects wrong indentation according to the level of nested braces.

  7. Ruby Script Beautifier5
  8. Ruby Beautifier accepts a command-line list of file names, creates a backup copy of each named file and beautifies the originals. If there is an indentation error (an imbalance of opening and closing keywords), the script will print an error message but will save the result anyway.

  9. Tabifier6
  10. The tabifier is a tool to properly indent computer code. The style it produces is a mix of my personal preferences for indentation plus what I could manage to make a program produce from dirty source. The tabifier currently supports CSS, HTML, and C Style code; the latter being anything that uses curly braces to start and end blocks, and semicolons to terminate statements.

    Screenshot7

  11. CSS Beautifier8
  12. This tool offers a variety of options, among them – Alphabetizing Feature and De-Capitalization Feature.

    Screenshot9

  13. Highlight.js10
  14. Highlight.js highlights syntax in code examples on blogs, forums and in fact on any web pages. It’s very easy to use because it works automatically: finds blocks of code, detects a language, highlights it. Also available as WordPress-Plugin and Firefox-extension. Suported languages: Python, Ruby, Perl, PHP, HTML, CSS, Django, JavaScript, VBScript, Delphi, Java, C++, SQL. Similar tools is offered by Google: Googles Javascript Code Prettifier.

    Screenshot11
    Screenshot

  15. PHP Formatter12
  16. PHP formatter adds comments after control structures, colors the output, links to the php-manual by inline-functions, removes comments and removes empty lines. There are 5 pre-defined layouts, but you can also define your own styles.

    Screenshot13

  17. PHP_Beautifier14
  18. A tool to beautify PHP 4 and PHP 5 source code – to run on your own server. Requires PHP 5.

  19. Lorins simple code beautifier for C++, C#, Java, and Javascript15
  20. You can use the source code of this beautifier to creat your own code formatters.

  21. Tidy16
  22. A classic. Tidy consists of many program libraries and comes and has many variations. E.g. you can use

    Commercial Solutions Link

  23. SourceFormatX Source Code Formatter & Beautifier23
  24. For developers. The tool supports neither HTML nor CSS; instead Javascript, VB, PHP, ASP, JSP, HTC, C, JAVA and more. Price: $36,99, Windows.

    Screenshot24

  25. Polystyle25
  26. Polystyle automatically reformats source code in your personal style. Polystyle learns your formatting style by examining examples of your code. It is another Windows-tool which supports Actionscript, ASP, C/C++, C#, CMAC, CSS, HTML, Java, Javascript, JSP, PHP, Pascal/Delphi, Perl, Python and Visual Basic. Price: 79$, can be used from the shell and Windows Explorer.

Footnotes Link

  1. 1 http://quickhighlighter.com/
  2. 2 http://quickhighlighter.com/
  3. 3 http://www.prettyprinter.de/
  4. 4 http://www.prettyprinter.de/
  5. 5 http://www.arachnoid.com/ruby/rubyBeautifier.html
  6. 6 http://tools.arantius.com/tabifier
  7. 7 http://tools.arantius.com/tabifier
  8. 8 http://www.lonniebest.com/FormatCSS/
  9. 9 http://www.lonniebest.com/FormatCSS/
  10. 10 http://softwaremaniacs.org/soft/highlight/en/
  11. 11 http://softwaremaniacs.org/soft/highlight/en/
  12. 12 http://formatter.gerbenvv.nl/version3/index.php?lang=en
  13. 13 http://formatter.gerbenvv.nl/version3/index.php?lang=en
  14. 14 http://beautifyphp.sourceforge.net/docs/
  15. 15 http://couponmeister.com/beautify.aspx
  16. 16 http://tidy.sourceforge.net/
  17. 17 http://perso.wanadoo.fr/ablavier/TidyGUI/
  18. 18 http://sourceforge.net/projects/tidy
  19. 19 http://www.w3.org/People/Raggett/tidy/
  20. 20 http://csstidy.sourceforge.net/
  21. 21 http://perltidy.sourceforge.net/
  22. 22 http://users.skynet.be/mgueury/mozilla/index.html
  23. 23 http://www.textrush.com/
  24. 24 http://www.textrush.com/
  25. 25 http://www.polystyle.com/
SmashingConf New York

Hold on, Tiger! Thank you for reading the article. Did you know that we also publish printed books and run friendly conferences – crafted for pros like you? Like SmashingConf Barcelona, on October 25–26, with smart design patterns and front-end techniques.

↑ Back to top Tweet itShare on Facebook

Sven is the co-founder and former CEO of Smashing Magazine. He's now writing at his Conterest Blog, where he focuses on blogs, content strategy and publishing — all in German.

  1. 1

    Better solution: (g)Vim with syntax highlighting.

    1
  2. 2

    Some useful tools ! Thank you ! :)

    0
  3. 3

    Ok, those are great. Has anyone seen a class library that performs code formatting for display in ASP.NET C#?

    I plan to use this on my blog to show code that I find useful.

    Thanks

    0
  4. 4

    I just use dreamweaver. It highlights code as well as anything Ive seen.

    0
  5. 5

    I use a free piece of software (Windows only) called HTML-Kit. It offers highlighting for just about every web language, a vast repository of plugins, and a built in FTP client (very handy for editing things on the fly).

    0
  6. 6

    I’m surprised Pygments was left off the list. For syntax highlighting, I don’t think it can be beat.

    0
  7. 7

    Awesome tips as usual.
    Though I would recommend saving a backup copy prior to using the tools. I know that sometimes TIDY can toss my whole page into a column. But it is still a useful tool, just remember it is a tool.

    0
  8. 8

    Karl L. Gechlik

    July 13, 2007 1:21 am

    I know some programers around here that can learn from this! I have forwarded it along. Thank you for the great article.

    Keep up the great work from your friends @ AskTheADmin

    0
  9. 9

    In regards to #9. Code Beautifier Plus….you should be shot dead at your keyboard if you use on(press), etc in actionscript.

    0
  10. 10

    For SQL, wangz.net provides a really nice SQL Instant Formatter

    0
  11. 11

    Anyone know of a Dreamweaver add-on that does this?

    0
  12. 12

    Make sure that you test your app after applying the modifications. There are cases when code formatters have caused errors in the code.

    Also, make sure you have taken a backup before saving the formatted code.

    4
  13. 13

    There is one more good commercial solution: Profactor Style Manager. This tool intergrates into VisualStudio and allows adjust all styles it can apply. Nice thing, I’ve used it once.

    0
  14. 14

    There is a nice csstidy version (same as http://www.cleancss.com) at http://www.codebeautifier.com with a portuguese version and a ‘select code’ feature. :)

    0
  15. 15

    As this post shows, c, c++, java, php, etc code formatters are about a dime a dozen.

    What I need is a free formatter for COBOL.

    That sure would make the task that I have to do SO much easier.

    Does anyone know of a good FREE COBOL code formatter?

    0
  16. 16

    marianne mcdougall

    July 12, 2007 9:22 pm

    Some very useful tools – Thank a lot guys.

    Mari
    G3 Creative (Scotland)

    2
  17. 17

    Seriously people, use Vim.

    It can do twice what any of these programs can combined.

    It has a steep learning curve, but so does programming; Vim is worth your time.

    0
  18. 18

    Michael Brennan-White

    July 13, 2007 6:50 am

    Eclipse is awesome, cross platform and provides almost all of the functionality of Dreamweaver, and it is free.

    You can use some of the wonderful plugins like CFEclipse and Aptana to provide syntax highlighting but also much more including the best tool for debugging purposes, code folding.

    0
  19. 19

    Thanks for this very helpful posting.

    I read about online backup on a daily dasis from an aggregator site,

    http://www.BackupReview.info

    I have been trying to find a source code for making a sofware for online backup service. Do you know of any such codes?

    Cheers.

    -2
  20. 20

    Is the javascript from google for prettifying code on webpages in this list?

    -1

↑ Back to top