问题
I encountered an indentation issue while combining html and jsp tags.
Steps to reproduce:
- File > New File (Ctrl+N)
- View > Syntax > Java > Java Server Page (JSP)
- Paste the following code:
<ul> <c:if test="${a > 0}"> <li>a</li> </c:if> </ul>
- Select all the content (Ctrl+A) and run Ctrl+Shift+P > Indentation: Reindent Lines
- 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*
(</(?!html)
([A-Za-z0-9]+(:[A-Za-z0-9]+)?)\b[^>]*>
|-->
|--%>
|<\?(php)?\s+(else(if)?|end(if|for(each)?|while))
|\}
)</string>
<key>increaseIndentPattern</key>
<string>(?x)
^\s*
<(?!\?|area|base|br|col|frame|hr|html|img|input|link|meta|param|[^>]*/>)
([A-Za-z0-9]+(:[A-Za-z0-9]+)?)(?=\s|>)\b[^>]*>(?!.*</\1>)
|<!--(?!.*-->)
|<%--(?!.*--%>)
|<\?php.+?\b(if|else(?:if)?|for(?:each)?|while)\b.*:(?!.*end\1)
|\{[^}"']*$
</string>
<key>bracketIndentNextLinePattern</key>
<string><!DOCTYPE(?!.*>)</string>
</dict>
</dict>
</plist>
Restart Sublime Text
来源:https://stackoverflow.com/questions/18691001/sublime-text-indentation-issue