问题描述
在emacs中编辑HTML时,是否有一种自动漂亮格式化一个标记的方法,可以改变这样的一种:
When editing HTML in emacs, is there a way to automatically pretty-format a blob of markup, changing something like this:
<table>
<tr>
<td>blah</td></tr></table>
...进入:
<table>
<tr>
<td>
blah
</td>
</tr>
</table>
推荐答案
默认情况下,当您访问<$ c $在Emacs(22或23)中的c> .html 文件,它将使您进入 html-mode
。这可能不是你想要的你可能想要 nxml-mode
,这是非常好看的。 nxml-mode
似乎只有Emacs 23,虽然你可以从。还有一个名为 nxml-mode
的Debian和Ubuntu软件包。您可以输入 nxml-mode
:
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
您可以查看nxml模式文档:
You can view nxml mode documentation with:
C-h i g (nxml-mode) RET
说,您可能必须使用等重新格式化您的xhtml示例。 nxml-mode
将从
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<table>
<tr>
<td>blah</td></tr></table>
</body>
to
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<table>
<tr>
<td>blah</td></tr></table>
</body>
</html>
但是,我没有看到更通用的功能,可以在某些xml标签上进行换行符。请注意, Cj
将插入一个具有适当缩进的新行,因此您可能可以执行一个快速宏或黑客攻击 defun
将会做你的表。
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.
这篇关于可以emacs为我重新缩进一大堆HTML吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!