Search in sources :

Example 1 with HtmlScriptContentProvider

use of com.intellij.lang.HtmlScriptContentProvider in project intellij-community by JetBrains.

the class HtmlHighlightingLexer method setEmbeddedLexer.

private void setEmbeddedLexer() {
    Lexer newLexer = null;
    if (hasSeenStyle()) {
        Lexer styleLexer = styleLexers.get(styleType);
        if (styleLexer == null) {
            if (hasSeenTag()) {
                IElementType currentStylesheetElementType = getCurrentStylesheetElementType();
                if (currentStylesheetElementType != null) {
                    Language language = currentStylesheetElementType.getLanguage();
                    styleLexer = SyntaxHighlighterFactory.getSyntaxHighlighter(language, null, null).getHighlightingLexer();
                } else if (ourStyleFileType != null) {
                    SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(ourStyleFileType, null, null);
                    LOG.assertTrue(highlighter != null, ourStyleFileType);
                    styleLexer = highlighter.getHighlightingLexer();
                } else {
                    styleLexer = null;
                }
                styleLexers.put(styleType, styleLexer);
            } else if (hasSeenAttribute()) {
                if (ourStyleFileType == null) {
                    styleLexer = null;
                } else {
                    SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(ourStyleFileType, null, null);
                    LOG.assertTrue(highlighter != null, ourStyleFileType);
                    styleLexer = highlighter.getHighlightingLexer();
                }
            }
        }
        newLexer = styleLexer;
    } else if (hasSeenScript()) {
        Lexer scriptLexer = scriptLexers.get(scriptType);
        if (scriptLexer == null) {
            if (hasSeenTag()) {
                HtmlScriptContentProvider provider = findScriptContentProvider(scriptType);
                if (provider != null) {
                    scriptLexer = provider.getHighlightingLexer();
                } else {
                    scriptLexer = SyntaxHighlighterFactory.getSyntaxHighlighter(PlainTextLanguage.INSTANCE, null, null).getHighlightingLexer();
                }
            } else if (hasSeenAttribute()) {
                SyntaxHighlighter syntaxHighlighter = ourInlineScriptFileType != null ? SyntaxHighlighterFactory.getSyntaxHighlighter(ourInlineScriptFileType, null, null) : null;
                scriptLexer = syntaxHighlighter != null ? syntaxHighlighter.getHighlightingLexer() : null;
            }
            scriptLexers.put(scriptType, scriptLexer);
        }
        newLexer = scriptLexer;
    } else {
        newLexer = createELLexer(newLexer);
    }
    if (newLexer != null) {
        embeddedLexer = newLexer;
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Language(com.intellij.lang.Language) PlainTextLanguage(com.intellij.openapi.fileTypes.PlainTextLanguage) HtmlScriptContentProvider(com.intellij.lang.HtmlScriptContentProvider) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter)

Aggregations

HtmlScriptContentProvider (com.intellij.lang.HtmlScriptContentProvider)1 Language (com.intellij.lang.Language)1 PlainTextLanguage (com.intellij.openapi.fileTypes.PlainTextLanguage)1 SyntaxHighlighter (com.intellij.openapi.fileTypes.SyntaxHighlighter)1 IElementType (com.intellij.psi.tree.IElementType)1