html – Sublime文本的缩进错误

前端之家收集整理的这篇文章主要介绍了html – Sublime文本的缩进错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在Sublime Text 3中使用 HTML中的自动缩进功能.我在html中有一些块注释并选择了Edit> Line> Reindent工作直到它命中块注释.

尝试在这里重新举例:

  1. <html>
  2. <head>
  3. <title>Testing Indent</title>
  4. </head>
  5. <body>
  6. <table>
  7. <tr>
  8. <td>
  9. Cell 1
  10. </td>
  11. </tr>
  12. <tr>
  13. Cell 2
  14. <!--Block Comment Here
  15. And a Little More Here
  16. -->
  17. </tr>
  18. </table>
  19. </body>
  20. </html>

结果是这样的:

  1. <html>
  2. <head>
  3. <title>Testing Indent</title>
  4. </head>
  5. <body>
  6. <table>
  7. <tr>
  8. <td>
  9. Cell 1
  10. </td>
  11. </tr>
  12. <tr>
  13. <td>
  14. Cell 2
  15. <!--Block Comment Here
  16. And a Little More Here
  17. -->
  18. </td>
  19. </tr>
  20. </table>
  21. </body>
  22. </html>

有什么想法吗?

解决方法

我在这里记录了这个问题: https://github.com/SublimeTextIssues/Core/issues/1271

出现此行为的原因是因为默认情况下,Sublime Text设置为保留注释的缩进.要禁用此功能

>如果尚未安装,请安装Package Control
>安装PackageResourceViewer(如果尚未安装):

>打开命令调色板
>选择包控制:安装包
>选择PackageResourceViewer

>打开命令调色板
>输入PRV:O
>选择PackageResourceViewer:打开资源
>选择默认
>选择缩进规则 – Comments.tmPreferences
>更改< true />在< key> preserveIndent< / key>下到< false />
>保存文件

Reindentation现在可以正常使用评论.

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

  1. <html>
  2. <head>
  3. <title>Testing Indent</title>
  4. </head>
  5. <body>
  6. <table>
  7. <tr>
  8. <td>
  9. Cell 1
  10. </td>
  11. </tr>
  12. <tr>
  13. Cell 2
  14. <!--
  15. Block Comment Here
  16. <td>
  17. And a Little More Here
  18. </td>
  19. -->
  20. </tr>
  21. </table>
  22. </body>
  23. </html>

会成为:

  1. <html>
  2. <head>
  3. <title>Testing Indent</title>
  4. </head>
  5. <body>
  6. <table>
  7. <tr>
  8. <td>
  9. Cell 1
  10. </td>
  11. </tr>
  12. <tr>
  13. Cell 2
  14. <!--
  15. Block Comment Here
  16. <td>
  17. And a Little More Here
  18. </td>
  19. -->
  20. </tr>
  21. </table>
  22. </body>
  23. </html>

去做这个:

>打开命令面板
>输入PRV:O
>选择PackageResourceViewer:打开资源
>选择HTML
>选择Miscellaneous.tmPreferences
>改变

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

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

  1. |--&gt;

  1. (?#|--&gt;)

(这评论结束评论正则表达式)
>保存

但是,当ST3的下一个版本可用时,如果它被正确修复,最好删除你的覆盖.这样,您将继续获得这些文件的更新,否则您将无法使用已保存的版本.去做这个:

>偏好 – >浏览包裹
>删除HTML文件
>进入默认文件夹并删除缩进规则 – Comments.tmPreferences文件

如果问题未在下一个版本中修复,则可以简单地重新创建这些更改.

猜你在找的HTML相关文章