QTextBrowser: assume Markdown is UTF-8
That's how CommonMark specifies it. The HTML codec-guessing algorithm was making it fall back to Latin1 in practice, which was screwing up any Unicode characters found in the markdown source. Change-Id: I4021adc4a68591ecfd56ef24971af53ce3e9c96d Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>bb10
parent
777c98ad9f
commit
07553d0353
|
|
@ -312,13 +312,17 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType
|
|||
if (data.type() == QVariant::String) {
|
||||
txt = data.toString();
|
||||
} else if (data.type() == QVariant::ByteArray) {
|
||||
if (type == QTextDocument::HtmlResource) {
|
||||
#if QT_CONFIG(textcodec)
|
||||
QByteArray ba = data.toByteArray();
|
||||
QTextCodec *codec = Qt::codecForHtml(ba);
|
||||
txt = codec->toUnicode(ba);
|
||||
QByteArray ba = data.toByteArray();
|
||||
QTextCodec *codec = Qt::codecForHtml(ba);
|
||||
txt = codec->toUnicode(ba);
|
||||
#else
|
||||
txt = data.toString();
|
||||
txt = data.toString();
|
||||
#endif
|
||||
} else {
|
||||
txt = QString::fromUtf8(data.toByteArray());
|
||||
}
|
||||
}
|
||||
if (Q_UNLIKELY(txt.isEmpty()))
|
||||
qWarning("QTextBrowser: No document for %s", url.toString().toLatin1().constData());
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
you’ll hope to see ❝quotes❞ ﹠1½ ⅔ ¼ ⅗ ⅚ ⅝ some “vulgar” fractions (pardon my «French»)
|
||||
|
|
@ -94,6 +94,8 @@ private slots:
|
|||
void urlEncoding();
|
||||
void sourceType_data();
|
||||
void sourceType();
|
||||
void unicode_data();
|
||||
void unicode();
|
||||
|
||||
private:
|
||||
TestBrowser *browser;
|
||||
|
|
@ -721,5 +723,31 @@ void tst_QTextBrowser::sourceType()
|
|||
QCOMPARE(maxHeadingLevel, expectedMaxHeadingLevel);
|
||||
}
|
||||
|
||||
void tst_QTextBrowser::unicode_data()
|
||||
{
|
||||
QTest::addColumn<QString>("sourceFile");
|
||||
QTest::addColumn<QTextDocument::ResourceType>("sourceType");
|
||||
QTest::addColumn<QString>("expectedText");
|
||||
|
||||
#if QT_CONFIG(textmarkdownreader)
|
||||
QTest::newRow("markdown with quotes and fractions") << "quotesAndFractions.md" << QTextDocument::MarkdownResource <<
|
||||
"you\u2019ll hope to see \u275Dquotes\u275E \uFE601\u00BD \u2154 \u00BC \u2157 \u215A \u215D some \u201Cvulgar\u201D fractions (pardon my \u00ABFrench\u00BB)";
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QTextBrowser::unicode()
|
||||
{
|
||||
QFETCH(QString, sourceFile);
|
||||
QFETCH(QTextDocument::ResourceType, sourceType);
|
||||
QFETCH(QString, expectedText);
|
||||
browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA(sourceFile)), sourceType);
|
||||
QTextFrame::iterator iterator = browser->document()->rootFrame()->begin();
|
||||
while (!iterator.atEnd()) {
|
||||
QString blockText = iterator++.currentBlock().text();
|
||||
if (!blockText.isEmpty())
|
||||
QCOMPARE(blockText, expectedText);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QTextBrowser)
|
||||
#include "tst_qtextbrowser.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue