Sublime Text indentation issue

心不动则不痛 提交于 2019-12-12 17:09:10

问题


I encountered an indentation issue while combining html and jsp tags.

Steps to reproduce:

  1. File > New File (Ctrl+N)
  2. View > Syntax > Java > Java Server Page (JSP)
  3. Paste the following code:
<ul>
   <c:if test="${a > 0}">
      <li>a</li>
   </c:if>
</ul>
  1. Select all the content (Ctrl+A) and run Ctrl+Shift+P > Indentation: Reindent Lines
  2. The result is:
<ul>
   <c:if test="${a > 0}">
      <li>a</li>
</c:if>
</ul>

Tested running Build 3047 under Windows 7 x64.

Any clues?


回答1:


For ST2 :

Open the html package and edit the Packages/HTML/Miscellaneous.tmPreferences file.

Replace the text with the one below. The below regex accepts basic jsp tags in <c:if> format & JSP comments. This will not format scriplets.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Miscellaneous</string>
    <key>scope</key>
    <string>text.html</string>
    <key>settings</key>
    <dict>
        <key>decreaseIndentPattern</key>
        <string>(?x)
        ^\s*
        (&lt;/(?!html)
          ([A-Za-z0-9]+(:[A-Za-z0-9]+)?)\b[^&gt;]*&gt;
        |--&gt;
        |--%&gt;
        |&lt;\?(php)?\s+(else(if)?|end(if|for(each)?|while))
        |\}
        )</string>
        <key>increaseIndentPattern</key>
        <string>(?x)
        ^\s*
        &lt;(?!\?|area|base|br|col|frame|hr|html|img|input|link|meta|param|[^&gt;]*/&gt;)
          ([A-Za-z0-9]+(:[A-Za-z0-9]+)?)(?=\s|&gt;)\b[^&gt;]*&gt;(?!.*&lt;/\1&gt;)
        |&lt;!--(?!.*--&gt;)
        |&lt;%--(?!.*--%&gt;)
        |&lt;\?php.+?\b(if|else(?:if)?|for(?:each)?|while)\b.*:(?!.*end\1)
        |\{[^}"']*$
        </string>
        <key>bracketIndentNextLinePattern</key>
        <string>&lt;!DOCTYPE(?!.*&gt;)</string>
    </dict>
</dict>
</plist>

Restart Sublime Text



来源:https://stackoverflow.com/questions/18691001/sublime-text-indentation-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!