18 QTextCharFormat entityFormat;
19 entityFormat.setForeground(Qt::red);
20 setFormatFor(Entity, entityFormat);
22 QTextCharFormat tagFormat;
23 tagFormat.setForeground(Qt::darkMagenta);
24 tagFormat.setFontWeight(QFont::Bold);
25 setFormatFor(Tag, tagFormat);
27 QTextCharFormat commentFormat;
28 commentFormat.setForeground(Qt::gray);
29 commentFormat.setFontItalic(
true);
30 setFormatFor(Comment, commentFormat);
32 QTextCharFormat attributeFormat;
33 attributeFormat.setForeground(Qt::black);
34 attributeFormat.setFontWeight(QFont::Bold);
35 setFormatFor(Attribute, attributeFormat);
37 QTextCharFormat valueFormat;
38 valueFormat.setForeground(Qt::blue);
39 setFormatFor(Value, valueFormat);
51 static const QChar tab = u'\t';
52 static const QChar space = u' ';
54 int state = previousBlockState();
55 qsizetype len = text.size();
64 QChar ch = text.at(pos);
66 if (QStringView{text}.sliced(pos).startsWith(
"<!--"_L1)) {
71 while (pos < len && text.at(pos) != space
72 && text.at(pos) != u'>'
73 && text.at(pos) != tab
74 && !QStringView{text}.sliced(pos).startsWith(
"/>"_L1)) {
77 if (QStringView{text}.sliced(pos).startsWith(
"/>"_L1))
79 setFormat(start, pos - start,
87 while (pos < len && text.at(pos++) != u';')
89 setFormat(start, pos - start,
99 for ( ; pos < len; ++pos) {
100 if (QStringView{text}.sliced(pos).startsWith(
"-->"_L1)) {
106 setFormat(start, pos - start, m_formats[Comment]);
109 QChar quote = QChar::Null;
111 QChar ch = text.at(pos);
112 if (quote.isNull()) {
114 if (ch ==
'\''_L1 || ch == u'"') {
116 }
else if (ch == u'>') {
118 setFormat(start, pos - start, m_formats[Tag]);
121 }
else if (QStringView{text}.sliced(pos).startsWith(
"/>"_L1)) {
123 setFormat(start, pos - start, m_formats[Tag]);
126 }
else if (ch != space && text.at(pos) != tab) {
130 while (pos < len && text.at(pos) != space
131 && text.at(pos) != tab
132 && text.at(pos) != u'=')
134 setFormat(start, pos - start, m_formats[Attribute]);
137 }
else if (ch == quote) {
141 setFormat(start, pos - start, m_formats[Value]);
148 setCurrentBlockState(state);