Can emacs re-indent a big blob of HTML for me?

后端 未结 10 2121
生来不讨喜
生来不讨喜 2021-01-29 20:09

When editing HTML in emacs, is there a way to automatically pretty-format a blob of markup, changing something like this:

  
10条回答
  •  渐次进展
    2021-01-29 20:56

    By default, when you visit a .html file in Emacs (22 or 23), it will put you in html-mode. That is probably not what you want. You probably want nxml-mode, which is seriously fancy. nxml-mode seems to only come with Emacs 23, although you can download it for earlier versions of emacs from the nXML web site. There is also a Debian and Ubuntu package named nxml-mode. You can enter nxml-mode with:

    M-x nxml-mode
    

    You can view nxml mode documentation with:

    C-h i g (nxml-mode) RET
    

    All that being said, you will probably have to use something like Tidy to re-format your xhtml example. nxml-mode will get you from

    
    
      
    
    
    blah

    to

    
    
      
      
        
    blah

    but I don't see a more general facility to do line breaks on certain xml tags as you want. Note that C-j will insert a new line with proper indentation, so you may be able to do a quick macro or hack up a defun that will do your tables.

提交回复
热议问题