Fix problem with HTML in title, feed title and excerpt
This commit is contained in:
parent
11cde07393
commit
b19e3dd06c
2 changed files with 12 additions and 3 deletions
14
src/post.cpp
14
src/post.cpp
|
@ -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("…", " ...").trimmed().replace("(\\s+)", " ").replace("\n", "");
|
||||
mExcerpt = html2text(post.value("excerpt").toString().remove(QRegExp("<[^>]*>")).replace("…", " ...").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();
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ private:
|
|||
bool mRead;
|
||||
bool mDontChangeRead;
|
||||
QString mJsonString;
|
||||
QString html2text(const QString htmlString);
|
||||
};
|
||||
|
||||
#endif // POST_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue