|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a HTML lexer with some additional methods. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.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 try: |
|
54 self.setFoldScriptComments( |
|
55 Preferences.getEditor("HtmlFoldScriptComments")) |
|
56 self.setFoldScriptHeredocs( |
|
57 Preferences.getEditor("HtmlFoldScriptHeredocs")) |
|
58 except AttributeError: |
|
59 pass |
|
60 try: |
|
61 self.setDjangoTemplates( |
|
62 Preferences.getEditor("HtmlDjangoTemplates")) |
|
63 self.setMakoTemplates(Preferences.getEditor("HtmlMakoTemplates")) |
|
64 except AttributeError: |
|
65 pass |
|
66 |
|
67 def isCommentStyle(self, style): |
|
68 """ |
|
69 Public method to check, if a style is a comment style. |
|
70 |
|
71 @param style style to check (integer) |
|
72 @return flag indicating a comment style (boolean) |
|
73 """ |
|
74 return style in [QsciLexerHTML.HTMLComment, |
|
75 QsciLexerHTML.ASPXCComment, |
|
76 QsciLexerHTML.SGMLComment, |
|
77 QsciLexerHTML.SGMLParameterComment, |
|
78 QsciLexerHTML.JavaScriptComment, |
|
79 QsciLexerHTML.JavaScriptCommentDoc, |
|
80 QsciLexerHTML.JavaScriptCommentLine, |
|
81 QsciLexerHTML.ASPJavaScriptComment, |
|
82 QsciLexerHTML.ASPJavaScriptCommentDoc, |
|
83 QsciLexerHTML.ASPJavaScriptCommentLine, |
|
84 QsciLexerHTML.VBScriptComment, |
|
85 QsciLexerHTML.ASPVBScriptComment, |
|
86 QsciLexerHTML.PythonComment, |
|
87 QsciLexerHTML.ASPPythonComment, |
|
88 QsciLexerHTML.PHPComment] |
|
89 |
|
90 def isStringStyle(self, style): |
|
91 """ |
|
92 Public method to check, if a style is a string style. |
|
93 |
|
94 @param style style to check (integer) |
|
95 @return flag indicating a string style (boolean) |
|
96 """ |
|
97 return style in [QsciLexerHTML.HTMLDoubleQuotedString, |
|
98 QsciLexerHTML.HTMLSingleQuotedString, |
|
99 QsciLexerHTML.SGMLDoubleQuotedString, |
|
100 QsciLexerHTML.SGMLSingleQuotedString, |
|
101 QsciLexerHTML.JavaScriptDoubleQuotedString, |
|
102 QsciLexerHTML.JavaScriptSingleQuotedString, |
|
103 QsciLexerHTML.JavaScriptUnclosedString, |
|
104 QsciLexerHTML.ASPJavaScriptDoubleQuotedString, |
|
105 QsciLexerHTML.ASPJavaScriptSingleQuotedString, |
|
106 QsciLexerHTML.ASPJavaScriptUnclosedString, |
|
107 QsciLexerHTML.VBScriptString, |
|
108 QsciLexerHTML.VBScriptUnclosedString, |
|
109 QsciLexerHTML.ASPVBScriptString, |
|
110 QsciLexerHTML.ASPVBScriptUnclosedString, |
|
111 QsciLexerHTML.PythonDoubleQuotedString, |
|
112 QsciLexerHTML.PythonSingleQuotedString, |
|
113 QsciLexerHTML.PythonTripleDoubleQuotedString, |
|
114 QsciLexerHTML.PythonTripleSingleQuotedString, |
|
115 QsciLexerHTML.ASPPythonDoubleQuotedString, |
|
116 QsciLexerHTML.ASPPythonSingleQuotedString, |
|
117 QsciLexerHTML.ASPPythonTripleDoubleQuotedString, |
|
118 QsciLexerHTML.ASPPythonTripleSingleQuotedString, |
|
119 QsciLexerHTML.PHPDoubleQuotedString, |
|
120 QsciLexerHTML.PHPSingleQuotedString] |
|
121 |
|
122 def defaultKeywords(self, kwSet): |
|
123 """ |
|
124 Public method to get the default keywords. |
|
125 |
|
126 @param kwSet number of the keyword set (integer) |
|
127 @return string giving the keywords (string) or None |
|
128 """ |
|
129 return QsciLexerHTML.keywords(self, kwSet) |