aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlbert Astals Cid <albert.astals.cid@kdab.com>2021-05-28 14:38:07 +0200
committerAlbert Astals Cid <albert.astals.cid@kdab.com>2021-06-04 10:17:28 +0200
commitcb20d7bcf8313fa3d39e07b37a7c9252fd28cde0 (patch)
treecfd0bb5e3d118f1f1869aee7d68caade1196f192
parent1c4ba17015fe99da48ce73fab75ecc60cf9cb975 (diff)
StyledText: Support all HTML entities
by using QTextHtmlParser::parseEntity StyledText is a "simpler/faster html" version of rich text, but parsing entities is cheap so I see no reason to not support all entities instead of just 6 of them Change-Id: I60e206f7cebd7645604a8f9372f7be0ebba027aa Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/quick/items/qquicktext.cpp2
-rw-r--r--src/quick/util/qquickstyledtext.cpp16
2 files changed, 5 insertions, 13 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index 153cdc0c10..a18ab824e2 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -2175,7 +2175,7 @@ void QQuickText::resetMaximumLineCount()
<img src="" align="top,middle,bottom" width="" height=""> - inline images
<ol type="">, <ul type=""> and <li> - ordered and unordered lists
<pre></pre> - preformatted
- &gt; &lt; &amp; &quot; &nbsp; &apos;
+ All entities
\endcode
\c Text.StyledText parser is strict, requiring tags to be correctly nested.
diff --git a/src/quick/util/qquickstyledtext.cpp b/src/quick/util/qquickstyledtext.cpp
index 96f5ce4d57..13ece608be 100644
--- a/src/quick/util/qquickstyledtext.cpp
+++ b/src/quick/util/qquickstyledtext.cpp
@@ -45,6 +45,7 @@
#include <qmath.h>
#include "qquickstyledtext_p.h"
#include <QQmlContext>
+#include <QtGui/private/qtexthtmlparser_p.h>
Q_LOGGING_CATEGORY(lcStyledText, "qt.quick.styledtext")
@@ -558,18 +559,9 @@ void QQuickStyledTextPrivate::parseEntity(const QChar *&ch, const QString &textI
while (!ch->isNull()) {
if (*ch == QLatin1Char(';')) {
auto entity = QStringView(textIn).mid(entityStart, entityLength);
- if (entity == QLatin1String("gt"))
- textOut += QChar(62);
- else if (entity == QLatin1String("lt"))
- textOut += QChar(60);
- else if (entity == QLatin1String("amp"))
- textOut += QChar(38);
- else if (entity == QLatin1String("apos"))
- textOut += QChar(39);
- else if (entity == QLatin1String("quot"))
- textOut += QChar(34);
- else if (entity == QLatin1String("nbsp"))
- textOut += QChar(QChar::Nbsp);
+ const QString parsedEntity = QTextHtmlParser::parseEntity(entity);
+ if (!parsedEntity.isNull())
+ textOut += parsedEntity;
else
qCWarning(lcStyledText) << "StyledText doesn't support entity" << entity;
return;