mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
xhtml conditional comment injection take 3
This commit is contained in:
@@ -44,6 +44,10 @@ public class XmlFileHighlighter extends SyntaxHighlighterBase {
|
||||
keys1.put(XmlTokenType.XML_COMMENT_START, XmlHighlighterColors.XML_COMMENT);
|
||||
keys1.put(XmlTokenType.XML_COMMENT_END, XmlHighlighterColors.XML_COMMENT);
|
||||
keys1.put(XmlTokenType.XML_COMMENT_CHARACTERS, XmlHighlighterColors.XML_COMMENT);
|
||||
keys1.put(XmlTokenType.XML_CONDITIONAL_COMMENT_END, XmlHighlighterColors.XML_COMMENT);
|
||||
keys1.put(XmlTokenType.XML_CONDITIONAL_COMMENT_END_START, XmlHighlighterColors.XML_COMMENT);
|
||||
keys1.put(XmlTokenType.XML_CONDITIONAL_COMMENT_START, XmlHighlighterColors.XML_COMMENT);
|
||||
keys1.put(XmlTokenType.XML_CONDITIONAL_COMMENT_START_END, XmlHighlighterColors.XML_COMMENT);
|
||||
|
||||
keys1.put(XmlTokenType.XML_START_TAG_START, XmlHighlighterColors.XML_TAG);
|
||||
keys1.put(XmlTokenType.XML_END_TAG_START, XmlHighlighterColors.XML_TAG);
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.intellij.lexer;
|
||||
|
||||
public class XHtmlHighlightingLexer extends HtmlHighlightingLexer {
|
||||
public XHtmlHighlightingLexer() {
|
||||
this(new XmlLexer());
|
||||
this(new XmlLexer(true));
|
||||
}
|
||||
|
||||
public XHtmlHighlightingLexer(Lexer baseLexer) {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class XHtmlLexer extends HtmlLexer {
|
||||
}
|
||||
|
||||
public XHtmlLexer() {
|
||||
this(new XmlLexer());
|
||||
this(new XmlLexer(true));
|
||||
}
|
||||
|
||||
protected boolean isHtmlTagState(int state) {
|
||||
|
||||
@@ -27,10 +27,15 @@ public class XmlLexer extends MergingLexerAdapter {
|
||||
XmlTokenType.XML_TAG_CHARACTERS,
|
||||
XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN,
|
||||
XmlTokenType.XML_PI_TARGET,
|
||||
XmlTokenType.XML_COMMENT_CHARACTERS,
|
||||
});
|
||||
|
||||
public XmlLexer() {
|
||||
this(new _XmlLexer(new __XmlLexer((Reader)null)));
|
||||
this(false);
|
||||
}
|
||||
|
||||
public XmlLexer(final boolean conditionalCommentsSupport) {
|
||||
this(new _XmlLexer(new __XmlLexer((Reader)null), conditionalCommentsSupport));
|
||||
}
|
||||
|
||||
public XmlLexer(Lexer baseLexer) {
|
||||
|
||||
+10
-13
@@ -16,7 +16,6 @@
|
||||
package com.intellij.psi.impl.source.html;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.html.HTMLLanguage;
|
||||
import com.intellij.lang.injection.MultiHostInjector;
|
||||
import com.intellij.lang.injection.MultiHostRegistrar;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -39,20 +38,18 @@ public class HtmlConditionalCommentInjector implements MultiHostInjector {
|
||||
if (host instanceof XmlComment) {
|
||||
final ASTNode comment = host.getNode();
|
||||
if (comment != null) {
|
||||
final ASTNode[] conditionalStarts = comment.getChildren(TokenSet.create(XmlTokenType.XML_CONDITIONAL_COMMENT_START_END));
|
||||
if (conditionalStarts.length > 0) {
|
||||
final ASTNode[] conditionalEnds = comment.getChildren(TokenSet.create(XmlTokenType.XML_CONDITIONAL_COMMENT_END_START));
|
||||
if (conditionalEnds.length > 0) {
|
||||
final ASTNode[] endOfEnd = comment.getChildren(TokenSet.create(XmlTokenType.XML_CONDITIONAL_COMMENT_END));
|
||||
if (endOfEnd.length > 0) {
|
||||
final ASTNode conditionalStart = comment.findChildByType(TokenSet.create(XmlTokenType.XML_CONDITIONAL_COMMENT_START_END));
|
||||
if (conditionalStart != null) {
|
||||
final ASTNode conditionalEnd = comment.findChildByType(TokenSet.create(XmlTokenType.XML_CONDITIONAL_COMMENT_END_START));
|
||||
if (conditionalEnd != null) {
|
||||
final ASTNode endOfEnd = comment.findChildByType(TokenSet.create(XmlTokenType.XML_CONDITIONAL_COMMENT_END));
|
||||
if (endOfEnd != null) {
|
||||
final TextRange textRange = host.getTextRange();
|
||||
final int startOffset = textRange.getStartOffset();
|
||||
|
||||
final ASTNode start = conditionalStarts[0];
|
||||
final ASTNode end = conditionalEnds[0];
|
||||
registrar.startInjecting(HTMLLanguage.INSTANCE).addPlace(null, null, (PsiLanguageInjectionHost)host,
|
||||
new TextRange(start.getTextRange().getEndOffset() - startOffset,
|
||||
end.getStartOffset() - startOffset)).doneInjecting();
|
||||
registrar.startInjecting(host.getParent().getLanguage()).addPlace(null, null, (PsiLanguageInjectionHost)host,
|
||||
new TextRange(
|
||||
conditionalStart.getTextRange().getEndOffset() - startOffset,
|
||||
conditionalEnd.getStartOffset() - startOffset)).doneInjecting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +321,9 @@ public class XmlParsing {
|
||||
advance();
|
||||
while (true) {
|
||||
final IElementType tt = token();
|
||||
if (tt == XML_COMMENT_CHARACTERS) {
|
||||
if (tt == XML_COMMENT_CHARACTERS|| tt == XML_CONDITIONAL_COMMENT_START
|
||||
|| tt == XML_CONDITIONAL_COMMENT_START_END || tt == XML_CONDITIONAL_COMMENT_END_START
|
||||
|| tt == XML_CONDITIONAL_COMMENT_END) {
|
||||
advance();
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user