Sublime Text 2:在一行中格式化 HTML 标签的内容 [英] Sublime Text 2: Format HTML tags' content in one line

查看:51
本文介绍了Sublime Text 2:在一行中格式化 HTML 标签的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我的情况与这里关于格式化 HTML 的所有线程都有些不同.此外,我已经安装了几乎所有 HTML 格式插件,结果好坏参半,但没有一个能真正解决我的问题.

Ok, my situation is a bit different than all the threads here about formatting HTML. Also, I've installed about every HTML formatting plugin out there with mixed results and none really solve my issue.

此外,配置这些插件可能很困难,因为我不是程序员,而且有些作者没有提供足够的信息来定制他们的插件.

Also, configuring these plugins can be difficult since I'm not a programmer and some authors don't provide enough information to customize their plugins.

目前唯一可以格式化我的 HTML 的插件是 HTMLTidy,问题是每个标签使用了太多空间.请参阅下面的 HTML 示例.

For now the only plugin that formats my HTML somewhat Ok is HTMLTidy, the problem is that it uses too much space per tag. See my HTML example below.

我也尝试了他们在这个主题 并且它仅在某种程度上适用于缩进,但不适用于真实"标记格式.

I also tried what they mentioned in this thread and it only works to some extent as far as indentation goes, but not really for 'true' markup formatting.

我想做的就是打开这个标记:

All I want to do is turn this markup:

<ul>
   <li>
     item here
   </li>
   <li>
     item here
   </li>
   <li>
     item here
   </li>
</ul>

或者这个:

<p>
   Content...
</p>

进入这个:

<ul>
   <li>item here</li>
   <li>item here</li>
   <li>item here</li>
</ul>

还有这个:

 <p>Content...</p>

将每个标签的内容与开始/结束标签分开一行对我来说是浪费空间.

Having the content of every tag in a separate line from the opening/closing tags is a waste of space for me.

知道如何通过在 TidyHTML 中或手动修改某些内容或任何其他方式来实现此目的吗?

Any idea how to accomplish this either by modifying something in TidyHTML or manually, or any other way for that matter?

提前致谢.

推荐答案

注意:此解决方案仅适用于 ST2,因为此时 (7/31/14) HTMLTidy 不适用于 ST3.

我想了一个临时解决方案,无论如何都不理想,但是...

Note: This solution works only in ST2, because at this moment (7/31/14) HTMLTidy is not available for ST3.

I figured a temporary solution, not ideal by any means, but...

  1. 转到:首选项 ->键绑定 - 用户.您将编辑文件 Default (Windows).sublime-keypmap.

  1. Go to: Preferences -> Key Bindings - User. You will be editing the file Default (Windows).sublime-keypmap.

将这两条指令添加到该文件中(注意,指令需要[ ]括号内):

Add these two instructions to that file (note that the instructions need to be inside the [ ] brackets):

 [
   { "keys": ["ctrl+shift+r"], "command": "reindent" , "args": {"single_line": false}},
   //Indent code -- http://stackoverflow.com/questions/8839753/formatting-html-code-using-sublime-text-2

   { "keys": ["ctrl+alt+t"], "command": "html_tidy"}
   //HTMLTidy key binding
 ]

  • 保存文件.

  • Save the file.

    确保您已安装 HTMLTidy.打开 HTMLTidy 的设置文件 HtmlTidy.sublime-settings:Preferences ->包设置 ->HtmlTidy ->设置 - 默认.

    Make sure you have HTMLTidy installed. Open HTMLTidy's Settings file HtmlTidy.sublime-settings: Preferences -> Package Settings -> HtmlTidy -> Settings - Default.

    查找"indent": true,(包括双引号和逗号)并将其更改为false.

    Look for "indent": true, (include double quotes and comma) and change it to false.

    保存文件.

    返回到您的 HTML 文件并选择您要在一行中格式化的代码的部分.是的,如果您选择整个标记 o_O,它就不起作用.它只会保留 标签内的内容,并删除其他所有内容(, 等).

    Go back to your HTML file and select a section of the code you want to format in one line. Yes, it doesn't work if you select the entire markup o_O. It will only leave what's inside the <body> tag, and it will delete everything else (<html>, <head>, etc).

    CTRL+ALT+T 执行 TidyHTML.这将缩小您的标记并使标签成为一行.

    Press CTRL+ALT+T to execute TidyHTML. This will shrink your markup and make the tags in one line.

    最后按 CTRL+SHIFT+R 执行缩进.

    Finally press CTRL+SHIFT+R to execute the indentation.

    祝你好运.

    这篇关于Sublime Text 2:在一行中格式化 HTML 标签的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆