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

后端 未结 10 1969
生来不讨喜
生来不讨喜 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:55

    The easiest way to do it is via command line.

    • Make sure you have tidy installed
    • type tidy -i -m <>

    Note that -m option replaces the newly tidied file with the old one. If you don't want that, you can type tidy -i -o <> <>

    The -i is for indentation. Alternatively, you can create a .tidyrc file that has settings such as

    indent: auto
    indent-spaces: 2
    wrap: 72
    markup: yes
    output-xml: no
    input-xml: no
    show-warnings: yes
    numeric-entities: yes
    quote-marks: yes
    quote-nbsp: yes
    quote-ampersand: no
    break-before-br: no
    uppercase-tags: no
    uppercase-attributes: no
    

    This way all you have to do is type tidy -o <> <>.

    For more just type man tidy on the command line.

提交回复
热议问题