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 "post.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <QTextDocument>
|
||||||
|
|
||||||
Post::Post(QObject *parent) : QObject(parent)
|
Post::Post(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -9,8 +10,8 @@ Post::Post(QObject *parent) : QObject(parent)
|
||||||
|
|
||||||
Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
|
Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
mTitle = post.value("title").toString().trimmed();
|
mTitle = html2text(post.value("title").toString().trimmed());
|
||||||
mFeedTitle = post.value("feed_title").toString().trimmed();
|
mFeedTitle = html2text(post.value("feed_title").toString().trimmed());
|
||||||
mId = post.value("id").toInt();
|
mId = post.value("id").toInt();
|
||||||
mFeedId = post.value("feed_id").toString().trimmed();
|
mFeedId = post.value("feed_id").toString().trimmed();
|
||||||
mAuthor = post.value("author").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());
|
timestamp.setTime_t(post.value("updated").toInt());
|
||||||
mDate = timestamp;
|
mDate = timestamp;
|
||||||
mContent = post.value("content").toString().trimmed();
|
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();
|
mStarred = post.value("marked").toBool();
|
||||||
mRead = !post.value("unread").toBool();
|
mRead = !post.value("unread").toBool();
|
||||||
mDontChangeRead = false;
|
mDontChangeRead = false;
|
||||||
|
@ -50,3 +51,10 @@ void Post::setDontChangeRead(bool r)
|
||||||
mDontChangeRead = r;
|
mDontChangeRead = r;
|
||||||
emit dontChangeReadChanged(mDontChangeRead);
|
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 mRead;
|
||||||
bool mDontChangeRead;
|
bool mDontChangeRead;
|
||||||
QString mJsonString;
|
QString mJsonString;
|
||||||
|
QString html2text(const QString htmlString);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // POST_H
|
#endif // POST_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue