开发者

Linux tool/editor that will nicely auto-format my code AFTER it's written

I'm looking for a tool or editor where I can paste in potentially messy code, be it HTML, Javascript, CSS, whatever, and properly take care of all indentation and spacing.

I use Geany but I don't see an option for this, surprisingly. I don't know if it开发者_运维问答's possible in vim or emacs. Any help would be appreciated.

Example HTML:

<!DOCTYPE html>
<html>
<body>
<ul>
<li>what a mess</li> 
</ul>
</body> 
</html>


Both vim and emacs will let you do what you ask. I believe in vim you want to use 'gg=G', and emacs is C-x C-M-\

I hope this helps.


There are some command line tools that can help (eg, 'indent' for C), but 'Edd's suggestion of Emacs and vi are probably the best that will work on all languages.


You could reformat/pretty-print the starting HTML and then work with the resulting file in the editor of your choice. For example on Linux you could use Tidy to clean up the HTML before editing it; you'd use a command like this,

tidy -indent ugly_file.html > nicer_file.html

(thank you to @shmit in this answer for the pointer to Tidy)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜