2016-07-07 95 views
6

我试图在Sublime Text 3中使用HTML中的自动缩进功能。我在html中选择了一些块注释,然后选择“编辑”>“行”>“重载”作品,直到遇到块注释为止。崇高文本的缩进错误

尝试这里的缩进例如:

<html> 
<head> 
<title>Testing Indent</title> 
</head> 
<body> 
<table> 
<tr> 
<td> 
Cell 1 
</td> 
</tr> 
<tr> 
Cell 2 
<!--Block Comment Here 
And a Little More Here 
--> 
</tr> 
</table> 
</body> 
</html> 

,它原来是这样的:

<html> 
<head> 
    <title>Testing Indent</title> 
</head> 
<body> 
    <table> 
     <tr> 
      <td> 
       Cell 1 
      </td> 
     </tr> 
     <tr> 
      <td> 
       Cell 2 
<!--Block Comment Here 
And a Little More Here 
--> 
</td> 
</tr> 
</table> 
</body> 
</html> 

有什么想法?

+0

它没有评论是否工作? –

+0

是的,当它没有注释块进行重新缩进时,缩进就好了。 –

+0

可以确认,确切的问题发生在我与ST3 3103 – Sebastianb

回答

13

我已经登录这里的问题:https://github.com/SublimeTextIssues/Core/issues/1271

这样做的原因行为是因为崇高的文本,默认情况下,设置保留意见的压痕。要禁用此:

  1. 安装Package Control如果尚未安装
  2. 安装PackageResourceViewer如果尚未安装:
    • 打开命令面板
    • 选择Package Control: Install Package
    • 选择PackageResourceViewer
  3. 打开命令面板
  4. 类型PRV: O
  5. 选择PackageResourceViewer: Open Resource
  6. 选择Default
  7. 选择Indentation Rules - Comments.tmPreferences
  8. 更改<true/><key>preserveIndent</key><false/>
  9. 保存文件

Reindentation现在可以正确处理评论。


我还建议编辑HTML缩进规则以忽略注释,以便它不会根据注释中的标记更改缩进。即否则

<html> 
<head> 
<title>Testing Indent</title> 
</head> 
<body> 
<table> 
<tr> 
<td> 
Cell 1 
</td> 
</tr> 
<tr> 
Cell 2 
<!-- 
Block Comment Here 
<td> 
And a Little More Here 
</td> 
--> 
</tr> 
</table> 
</body> 
</html> 

将成为:

<html> 
<head> 
    <title>Testing Indent</title> 
</head> 
<body> 
    <table> 
     <tr> 
      <td> 
       Cell 1 
      </td> 
     </tr> 
     <tr> 
      Cell 2 
      <!-- 
      Block Comment Here 
      <td> 
       And a Little More Here 
      </td> 
     --> 
    </tr> 
</table> 
</body> 
</html> 

要做到这一点:

  1. 打开命令调色板
  2. 类型PRV: O
  3. 选择PackageResourceViewer: Open Resource
  4. 选择HTML
  5. 选择Miscellaneous.tmPreferences
  6. 变化

    <key>scope</key> 
    <string>text.html</string> 
    

    <key>scope</key> 
    <string>text.html - comment</string> 
    

    |--&gt; 
    

    (?#|--&gt;) 
    

    (这注释掉注释结束正则表达式)

  7. 保存

然而,当ST3的下一个版本是可用的,这可能是一个好主意,然后删除覆盖,以防万一它被正确地固定。这样,您将继续获得这些文件的更新,否则您将被保存在您保存的版本中。要做到这一点:

  1. Preferences - >Browse Packages
  2. 删除HTML文件夹
  3. 进入该文件夹Default并删除Indentation Rules - Comments.tmPreferences文件

如果该问题不固定,在未来构建,您可以简单地重新创建这些更改。

+1

太棒了。非常好的答案。我遵循这些步骤,一切按预期工作。我很欣赏细节的程度。我会密切关注未来的更新。 –

+1

谢谢队友! – Ash

+0

该软件包还可以帮助“修复”已压缩缩进的文件:https://packagecontrol.io/packages/Normalize%20Indentation – kursus

1

在Sublime Text 3(构建3103和3114)中尝试了您的示例,并且您是正确的,缩进会在找到注释块时中断。

显然,重新注入功能总是pretty weak而HTML并不是它不起作用的唯一上下文(编辑:在PHP中也证实了,几乎相同的行为)。

如果它尚未提交,我建议submitting the issue

+0

谢谢,我会看看,并提交它不存在的问题。 –

+0

有这个问题https://github.com/SublimeTextIssues/Core/issues/1271 – AdamS