23 #include "htmlhighlighter.h"
25 namespace KPIMTextEdit {
27 class HtmlHighlighterPrivate
52 HtmlHighlighterPrivate()
54 colors[DocType] =
QColor( 192, 192, 192 );
55 colors[Entity] =
QColor( 128, 128, 128 );
56 colors[Tag] =
QColor( 136, 18, 128 );
57 colors[Comment] =
QColor( 35, 110, 37 );
58 colors[AttributeName] =
QColor( 153, 69, 0 );
59 colors[AttributeValue] =
QColor( 36, 36, 170 );
69 HtmlHighlighter::~HtmlHighlighter()
74 void HtmlHighlighter::highlightBlock(
const QString &text )
76 int state = previousBlockState();
83 case HtmlHighlighterPrivate::State_Text:
89 state = HtmlHighlighterPrivate::State_Comment;
92 state = HtmlHighlighterPrivate::State_DocType;
94 state = HtmlHighlighterPrivate::State_TagStart;
100 while ( pos < len && text.
at( pos++ ) !=
QLatin1Char(
';' ) )
102 setFormat( start, pos - start, d->colors[HtmlHighlighterPrivate::Entity] );
109 case HtmlHighlighterPrivate::State_Comment:
111 while ( pos < len ) {
114 state = HtmlHighlighterPrivate::State_Text;
120 setFormat( start, pos - start, d->colors[HtmlHighlighterPrivate::Comment] );
123 case HtmlHighlighterPrivate::State_DocType:
125 while ( pos < len ) {
129 state = HtmlHighlighterPrivate::State_Text;
133 setFormat( start, pos - start, d->colors[HtmlHighlighterPrivate::DocType] );
137 case HtmlHighlighterPrivate::State_TagStart:
139 while ( pos < len ) {
143 state = HtmlHighlighterPrivate::State_Text;
148 state = HtmlHighlighterPrivate::State_TagName;
155 case HtmlHighlighterPrivate::State_TagName:
157 while ( pos < len ) {
162 state = HtmlHighlighterPrivate::State_InsideTag;
166 state = HtmlHighlighterPrivate::State_Text;
170 setFormat( start, pos - start, d->colors[HtmlHighlighterPrivate::Tag] );
174 case HtmlHighlighterPrivate::State_InsideTag:
177 while ( pos < len ) {
186 state = HtmlHighlighterPrivate::State_Text;
192 state = HtmlHighlighterPrivate::State_AttributeName;
201 case HtmlHighlighterPrivate::State_AttributeName:
204 while ( pos < len ) {
209 state = HtmlHighlighterPrivate::State_AttributeValue;
214 state = HtmlHighlighterPrivate::State_InsideTag;
219 setFormat( start, pos - start, d->colors[HtmlHighlighterPrivate::AttributeName] );
223 case HtmlHighlighterPrivate::State_AttributeValue:
227 while ( pos < len ) {
233 state = HtmlHighlighterPrivate::State_SingleQuote;
239 state = HtmlHighlighterPrivate::State_DoubleQuote;
248 if ( state == HtmlHighlighterPrivate::State_AttributeValue ) {
252 while ( pos < len ) {
262 state = HtmlHighlighterPrivate::State_InsideTag;
263 setFormat( start, pos - start, d->colors[HtmlHighlighterPrivate::AttributeValue] );
269 case HtmlHighlighterPrivate::State_SingleQuote:
272 while ( pos < len ) {
280 state = HtmlHighlighterPrivate::State_InsideTag;
282 setFormat( start, pos - start, d->colors[HtmlHighlighterPrivate::AttributeValue] );
286 case HtmlHighlighterPrivate::State_DoubleQuote:
289 while ( pos < len ) {
297 state = HtmlHighlighterPrivate::State_InsideTag;
299 setFormat( start, pos - start, d->colors[HtmlHighlighterPrivate::AttributeValue] );
305 setCurrentBlockState( state );
QString mid(int position, int n) const
const QChar at(int position) const