Commit f8606279 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Improve autotest

parent f02d4d53
......@@ -35,7 +35,8 @@ void TextHTMLBuilderTest::testHtmlText_data()
QTest::addColumn<QString>("text");
QTest::addColumn<QString>("regexpText");
QTest::newRow("link") << QStringLiteral("A <a href=\"http://www.kde.org\">link</a> to KDE.") << QStringLiteral("^<p>A <a href=\"http://www.kde.org\">link</a> to KDE.</p>\\n$");
//QTest::newRow("text with espace at begin") << QStringLiteral(" foo") << QStringLiteral("^<p>A <a href=\"http://www.kde.org\">link</a> to KDE.</p>\\n$");
QTest::newRow("text with espace") << QStringLiteral(" foo") << QStringLiteral("^<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foo</p>\\n$");
QTest::newRow("text with espace at begin") << QStringLiteral(" foo") << QStringLiteral("^<p>&nbsp;foo</p>\\n$");
}
void TextHTMLBuilderTest::testHtmlText()
......@@ -44,7 +45,7 @@ void TextHTMLBuilderTest::testHtmlText()
QFETCH(QString, regexpText);
auto doc = new QTextDocument();
doc->setHtml(text);
doc->setPlainText(text);
auto hb = new KPIMTextEdit::TextHTMLBuilder();
auto md = new Grantlee::MarkupDirector(hb);
......
......@@ -22,6 +22,7 @@
#include <QList>
#include <QTextDocument>
#include <QDebug>
namespace KPIMTextEdit {
......@@ -461,13 +462,36 @@ void TextHTMLBuilder::endTableCell()
void TextHTMLBuilder::appendLiteralText(const QString &text)
{
Q_D(TextHTMLBuilder);
d->m_text.append(text.toHtmlEscaped());
qDebug() << " appendLiteralText " << text;
const QString textEscaped = text.toHtmlEscaped();
QString textEscapedResult;
for (int i = 0, total = textEscaped.count(); i < total; ++i) {
const QChar c = textEscaped.at(i);
if (c == QLatin1Char(' ')) {
if (i == 0) {
textEscapedResult += QStringLiteral("&nbsp;");
} else {
if (i + 1 < textEscaped.count() && (textEscaped.at(i + 1) == QLatin1Char(' '))) {
textEscapedResult += QStringLiteral("&nbsp;");
} else {
textEscapedResult += c;
}
}
} else {
textEscapedResult += c;
}
}
d->m_text.append(textEscapedResult);
qDebug() << " d->m_text " << d->m_text;
}
void TextHTMLBuilder::appendRawText(const QString &text)
{
Q_D(TextHTMLBuilder);
qDebug() << " appendRawText " << text;
d->m_text.append(text);
qDebug() << " d->m_text " << d->m_text;
}
QString TextHTMLBuilder::getResult()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment