src/eric7/QScintilla/Lexers/LexerHTML.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a HTML lexer with some additional methods.
8 """
9
10 import contextlib
11
12 from PyQt6.Qsci import QsciLexerHTML
13
14 from .Lexer import Lexer
15 import Preferences
16
17
18 class LexerHTML(Lexer, QsciLexerHTML):
19 """
20 Subclass to implement some additional lexer dependant methods.
21 """
22 def __init__(self, parent=None):
23 """
24 Constructor
25
26 @param parent parent widget of this lexer
27 """
28 QsciLexerHTML.__init__(self, parent)
29 Lexer.__init__(self)
30
31 self.streamCommentString = {
32 'start': '<!-- ',
33 'end': ' -->'
34 }
35
36 self.keywordSetDescriptions = [
37 self.tr("HTML elements and attributes"),
38 self.tr("JavaScript keywords"),
39 self.tr("VBScript keywords"),
40 self.tr("Python keywords"),
41 self.tr("PHP keywords"),
42 self.tr("SGML and DTD keywords"),
43 ]
44
45 def initProperties(self):
46 """
47 Public slot to initialize the properties.
48 """
49 self.setFoldPreprocessor(Preferences.getEditor("HtmlFoldPreprocessor"))
50 self.setCaseSensitiveTags(
51 Preferences.getEditor("HtmlCaseSensitiveTags"))
52 self.setFoldCompact(Preferences.getEditor("AllFoldCompact"))
53 with contextlib.suppress(AttributeError):
54 self.setFoldScriptComments(
55 Preferences.getEditor("HtmlFoldScriptComments"))
56 self.setFoldScriptHeredocs(
57 Preferences.getEditor("HtmlFoldScriptHeredocs"))
58 with contextlib.suppress(AttributeError):
59 self.setDjangoTemplates(
60 Preferences.getEditor("HtmlDjangoTemplates"))
61 self.setMakoTemplates(Preferences.getEditor("HtmlMakoTemplates"))
62
63 def isCommentStyle(self, style):
64 """
65 Public method to check, if a style is a comment style.
66
67 @param style style to check (integer)
68 @return flag indicating a comment style (boolean)
69 """
70 return style in [QsciLexerHTML.HTMLComment,
71 QsciLexerHTML.ASPXCComment,
72 QsciLexerHTML.SGMLComment,
73 QsciLexerHTML.SGMLParameterComment,
74 QsciLexerHTML.JavaScriptComment,
75 QsciLexerHTML.JavaScriptCommentDoc,
76 QsciLexerHTML.JavaScriptCommentLine,
77 QsciLexerHTML.ASPJavaScriptComment,
78 QsciLexerHTML.ASPJavaScriptCommentDoc,
79 QsciLexerHTML.ASPJavaScriptCommentLine,
80 QsciLexerHTML.VBScriptComment,
81 QsciLexerHTML.ASPVBScriptComment,
82 QsciLexerHTML.PythonComment,
83 QsciLexerHTML.ASPPythonComment,
84 QsciLexerHTML.PHPComment]
85
86 def isStringStyle(self, style):
87 """
88 Public method to check, if a style is a string style.
89
90 @param style style to check (integer)
91 @return flag indicating a string style (boolean)
92 """
93 return style in [QsciLexerHTML.HTMLDoubleQuotedString,
94 QsciLexerHTML.HTMLSingleQuotedString,
95 QsciLexerHTML.SGMLDoubleQuotedString,
96 QsciLexerHTML.SGMLSingleQuotedString,
97 QsciLexerHTML.JavaScriptDoubleQuotedString,
98 QsciLexerHTML.JavaScriptSingleQuotedString,
99 QsciLexerHTML.JavaScriptUnclosedString,
100 QsciLexerHTML.ASPJavaScriptDoubleQuotedString,
101 QsciLexerHTML.ASPJavaScriptSingleQuotedString,
102 QsciLexerHTML.ASPJavaScriptUnclosedString,
103 QsciLexerHTML.VBScriptString,
104 QsciLexerHTML.VBScriptUnclosedString,
105 QsciLexerHTML.ASPVBScriptString,
106 QsciLexerHTML.ASPVBScriptUnclosedString,
107 QsciLexerHTML.PythonDoubleQuotedString,
108 QsciLexerHTML.PythonSingleQuotedString,
109 QsciLexerHTML.PythonTripleDoubleQuotedString,
110 QsciLexerHTML.PythonTripleSingleQuotedString,
111 QsciLexerHTML.ASPPythonDoubleQuotedString,
112 QsciLexerHTML.ASPPythonSingleQuotedString,
113 QsciLexerHTML.ASPPythonTripleDoubleQuotedString,
114 QsciLexerHTML.ASPPythonTripleSingleQuotedString,
115 QsciLexerHTML.PHPDoubleQuotedString,
116 QsciLexerHTML.PHPSingleQuotedString]
117
118 def defaultKeywords(self, kwSet):
119 """
120 Public method to get the default keywords.
121
122 @param kwSet number of the keyword set (integer)
123 @return string giving the keywords (string) or None
124 """
125 return QsciLexerHTML.keywords(self, kwSet)

eric ide

mercurial