Fix problem with HTML in title, feed title and excerpt

This commit is contained in:
Jeena 2016-07-22 21:03:00 +02:00
parent 11cde07393
commit b19e3dd06c
2 changed files with 12 additions and 3 deletions

View file

@ -1,6 +1,7 @@
#include "post.h"
#include <QDebug>
#include <QJsonDocument>
#include <QTextDocument>
Post::Post(QObject *parent) : QObject(parent)
{
@ -9,8 +10,8 @@ Post::Post(QObject *parent) : QObject(parent)
Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
{
mTitle = post.value("title").toString().trimmed();
mFeedTitle = post.value("feed_title").toString().trimmed();
mTitle = html2text(post.value("title").toString().trimmed());
mFeedTitle = html2text(post.value("feed_title").toString().trimmed());
mId = post.value("id").toInt();
mFeedId = post.value("feed_id").toString().trimmed();
mAuthor = post.value("author").toString().trimmed();
@ -20,7 +21,7 @@ Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
timestamp.setTime_t(post.value("updated").toInt());
mDate = timestamp;
mContent = post.value("content").toString().trimmed();
mExcerpt = post.value("excerpt").toString().remove(QRegExp("<[^>]*>")).replace("&hellip;", " ...").trimmed().replace("(\\s+)", " ").replace("\n", "");
mExcerpt = html2text(post.value("excerpt").toString().remove(QRegExp("<[^>]*>")).replace("&hellip;", " ...").trimmed().replace("(\\s+)", " ").replace("\n", ""));
mStarred = post.value("marked").toBool();
mRead = !post.value("unread").toBool();
mDontChangeRead = false;
@ -50,3 +51,10 @@ void Post::setDontChangeRead(bool r)
mDontChangeRead = r;
emit dontChangeReadChanged(mDontChangeRead);
}
QString Post::html2text(const QString htmlString)
{
QTextDocument doc;
doc.setHtml(htmlString);
return doc.toPlainText();
}

View file

@ -64,6 +64,7 @@ private:
bool mRead;
bool mDontChangeRead;
QString mJsonString;
QString html2text(const QString htmlString);
};
#endif // POST_H