[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepimlibs/kblog
From:       Mike Arthur <mike () mikearthur ! co ! uk>
Date:       2008-08-12 16:16:51
Message-ID: 1218557811.287164.8920.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 845920 by mikearthur:

When converting a journal to a post, clean up the Qt HTML output.

 M  +27 -1     blogpost.cpp  
 M  +1 -0      blogpost_p.h  


--- trunk/KDE/kdepimlibs/kblog/blogpost.cpp #845919:845920
@@ -67,7 +67,12 @@
   d_ptr->mJournalId = journal.uid();
   d_ptr->mStatus = New;
   d_ptr->mTitle = journal.summary();
-  d_ptr->mContent = journal.description();
+  if (journal.descriptionIsRich()) {
+    d_ptr->mContent = d_ptr->cleanRichText(journal.description());
+  }
+  else {
+    d_ptr->mContent = journal.description();
+  }
   d_ptr->mCategories = journal.categories();
   d_ptr->mCreationDateTime = journal.dtStart();
 }
@@ -318,5 +323,26 @@
   return *this;
 }
 
+QString BlogPostPrivate::cleanRichText( QString richText ) const
+{
+  QRegExp getBodyContents("<body[^>]*>(.*)</body>");
+  if ( getBodyContents.indexIn( richText ) )
+  {
+    // Get anything inside but excluding the body tags
+    richText = getBodyContents.cap(1);
+    // Get rid of any whitespace
+    richText.replace(QRegExp("^\\s+"),"");
+  }
+  // Get rid of styled paragraphs
+  richText.replace(QRegExp("<p style=\"[^\"]*\">"),"<p>");
+
+  // If we're left with empty content then return a clean empty string
+  if ( richText == "<p></p>" ) {
+    richText = QString();
+  }
+
+  return richText;
+}
+
 } // namespace KBlog
 
--- trunk/KDE/kdepimlibs/kblog/blogpost_p.h #845919:845920
@@ -52,6 +52,7 @@
     BlogPost::Status mStatus;
     KDateTime mCreationDateTime;
     KDateTime mModificationDateTime;
+    QString cleanRichText(QString richText) const;
 };
 
 } // namespace
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic