95cfa90c09c83567a0eb671ad89ac95264feb993
1 # BiaWeb Website content manager (c) 2010 V.Harishankar
2 # HTML highlighter class
6 class SimpleHtmlHighlighter (PyQt4
.QtGui
.QSyntaxHighlighter
):
7 def __init__ (self
, document
):
8 PyQt4
.QtGui
.QSyntaxHighlighter
.__init
__ (self
, document
)
10 def highlightBlock (self
, text
):
11 # define the character highlight formats
12 charfmt1
= PyQt4
.QtGui
.QTextCharFormat ()
13 charfmt1
.setFontWeight (PyQt4
.QtGui
.QFont
.Bold
)
14 charfmt1
.setForeground (PyQt4
.QtCore
.Qt
.blue
)
16 charfmt2
= PyQt4
.QtGui
.QTextCharFormat ()
17 charfmt2
.setForeground (PyQt4
.QtCore
.Qt
.darkGreen
)
19 # matching regular expressions
20 htmltagexps
= [ (PyQt4
.QtCore
.QRegExp ("<[^<>]+>"), charfmt1
),
21 (PyQt4
.QtCore
.QRegExp ("\"[^\"]+\""), charfmt2
)
24 # run through the list of regular expressions to highlight
25 for htmltagexp
, charfmt
in htmltagexps
:
26 index
= htmltagexp
.indexIn (text
)
28 length
= htmltagexp
.matchedLength ()
29 # self.setFormat is actual code highlighting
30 self
.setFormat (index
, length
, charfmt
)
31 index
= htmltagexp
.indexIn (text
, index
+ length
)