From b19e3dd06cd2a25767b0ee24793967891bc79530 Mon Sep 17 00:00:00 2001 From: Jeena Date: Fri, 22 Jul 2016 21:03:00 +0200 Subject: [PATCH] Fix problem with HTML in title, feed title and excerpt --- src/post.cpp | 14 +++++++++++--- src/post.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/post.cpp b/src/post.cpp index e81c1f2..5a6f151 100644 --- a/src/post.cpp +++ b/src/post.cpp @@ -1,6 +1,7 @@ #include "post.h" #include #include +#include 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(); +} diff --git a/src/post.h b/src/post.h index 6c4cd18..66a13dd 100644 --- a/src/post.h +++ b/src/post.h @@ -64,6 +64,7 @@ private: bool mRead; bool mDontChangeRead; QString mJsonString; + QString html2text(const QString htmlString); }; #endif // POST_H