[Bug 207779] Kmail removes empty lines in HTML
Torgny Nyblom
kde at nyblom.org
Sat Jan 1 20:21:21 GMT 2011
https://bugs.kde.org/show_bug.cgi?id=207779
Torgny Nyblom <kde at nyblom.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
--- Comment #13 from Torgny Nyblom <kde nyblom org> 2011-01-01 21:21:18 ---
commit 366e26a75817bcf246bfe04453c5f69e198eee93
branch master
Author: Torgny Nyblom <kde at nyblom.org>
Date: Sat Jan 1 21:17:50 2011 +0100
Do not remove empty lines in HTML for Outlook
Thanks to Frank Vanderham for the patch.
BUG: 207779
diff --git a/messagecomposer/CMakeLists.txt b/messagecomposer/CMakeLists.txt
index 477bc29..53933fa 100644
--- a/messagecomposer/CMakeLists.txt
+++ b/messagecomposer/CMakeLists.txt
@@ -84,7 +84,7 @@ kde4_add_kcfg_files(messagecomposer_src
kde4_add_library( messagecomposer ${LIBRARY_TYPE} ${messagecomposer_src} )
target_link_libraries( messagecomposer ${KDE4_KIO_LIBS}
${KDEPIMLIBS_KMIME_LIBS} ${KDEPIMLIBS_AKONADI_KMIME_LIBS}
${KDEPIMLIBS_AKONADI_LIBS} ${KDEPIMLIBS_MAILTRANSPORT_LIBS}
${KDEPIMLIBS_KPIMTEXTEDIT_LIBS} ${KDEPIMLIBS_KPIMIDENTITIES_LIBS}
- messagecore messageviewer templateparser kleo kdepim ${QGPGME_LIBRARIES} )
+ messagecore messageviewer templateparser kleo kdepim ${QGPGME_LIBRARIES}
${QT_QTWEBKIT_LIBRARY} )
set_target_properties( messagecomposer PROPERTIES VERSION
${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
install( TARGETS messagecomposer ${INSTALL_TARGETS_DEFAULT_ARGS} )
diff --git a/messagecomposer/kmeditor.cpp b/messagecomposer/kmeditor.cpp
index 7ab1288..30e9b4c 100644
--- a/messagecomposer/kmeditor.cpp
+++ b/messagecomposer/kmeditor.cpp
@@ -39,6 +39,10 @@
#include <QShortcut>
#include <QTextLayout>
#include <QTimer>
+#include <QWebElement>
+#include <QWebElementCollection>
+#include <QWebFrame>
+#include <QWebPage>
using namespace KPIMTextEdit;
@@ -686,4 +690,39 @@ void KMeditor::fillComposerTextPart ( TextPart* textPart )
const
}
}
+QString KMeditor::toCleanHtml() const
+{
+ const QString textEditHTML = toHtml();
+
+ // construct a non-visual QWebPage - that'll hook us into Qt's HTML parser
from WebKit
+ QWebPage webpage( 0 );
+ QWebFrame *webframe = webpage.mainFrame();
+ webframe->setHtml( textEditHTML );
+ QWebElement docElement = webframe->documentElement();
+
+ // fix 1 - empty lines should show as empty lines - MS Outlook treats
margin-top:0px; as
+ // a non-existing line.
+ // Although we can simply remove the margin-top style property, we still get
unwanted results
+ // if you have three or more empty lines. It's best to replace empty <p>
elements with <br>.
+ // As per http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Strict, <br>
elements are still proper
+ // HTML.
+ QWebElementCollection paragraphs = docElement.findAll( QString::fromAscii(
"p" ) );
+ foreach (QWebElement paraElement, paragraphs) {
+ QString paraContent = paraElement.toPlainText();
+ // Only make a change when the paragraph content is empty
+ if ( paraContent.isEmpty() ) {
+ paraElement.replace( QString::fromAscii( "<br />" ) );
+ }
+ }
+ // fix 2 - ordered and unordered lists - MS Outlook treats margin-left:0px;
as
+ // a non-existing number; e.g: "1. First item" turns into "First Item"
+ QWebElementCollection lists = docElement.findAll( QString::fromAscii(
"ol,ul" ) );
+ foreach (QWebElement listElement, lists) {
+ //TODO in the future, we may want to explicitly set the margin-left=0 with
the Composer window itself, which
+ // would be overwritten here again. This will likely require a rewrite
of the KMEditor altogether, though.
+ listElement.setStyleProperty( QString::fromAscii( "margin-left" ),
QString( ) );
+ }
+ return webframe->toHtml();
+}
+
#include "kmeditor.moc"
diff --git a/messagecomposer/kmeditor.h b/messagecomposer/kmeditor.h
index af9bf89..b24e3ba 100644
--- a/messagecomposer/kmeditor.h
+++ b/messagecomposer/kmeditor.h
@@ -176,6 +176,12 @@ class MESSAGECOMPOSER_EXPORT KMeditor : public
KPIMTextEdit::TextEdit
*/
void fillComposerTextPart( Message::TextPart* textPart ) const;
+ /**
+ * Overloaded function from KRichTextEdit to deal with problems viewing
HTML formatted
+ * emails in MS Outlook.
+ */
+ QString toCleanHtml() const;
+
public Q_SLOTS:
void slotAddQuotes();
--
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the Kdepim-bugs
mailing list