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

List:       kde-commits
Subject:    playground/network/kblogger/src
From:       Antonio Aloisio <antonio.aloisio () gmail ! com>
Date:       2007-05-03 12:55:50
Message-ID: 1178196950.832957.9762.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 660693 by aloisio:

spanKill replaced with richtextToHtml; added htmlToRichtext; code cleaned

 M  +28 -34    kbloggereditor.cpp  
 M  +3 -2      kbloggereditor.h  


--- trunk/playground/network/kblogger/src/kbloggereditor.cpp #660692:660693
@@ -471,19 +471,23 @@
 	VisualTextEditor->setCheckSpellingEnabled ( isCheckSpellingEnabled );
 }
 
-QString KBloggerEditor::spanKill(const QString& text)
+QString KBloggerEditor::richtextToHtml(const QString& text)
 {
 	QString dirtyText=text;
-	QRegExp spanKillExp("(<span style=\")([^\".]*)(\">)([^<]*)(</span>)");
+	dirtyText.remove ( "<html><head><meta name=\"qrichtext\" content=\"1\" /></head>" \
); +	dirtyText.remove ( QRegExp ( "<body[^<]+>\n" ) );
+	dirtyText.remove ( QRegExp ("</body></html>" ));
+
+	QRegExp richtextToHtmlExp("(<span style=\")([^\".]*)(\">)([^<]*)(</span>)");
 	
-	while ( spanKillExp.search( dirtyText ) != -1 ) {
+	while ( richtextToHtmlExp.search( dirtyText ) != -1 ) {
 	  QString newSpanStart, newSpanEnd, SpanStartA, SpanStartB, SpanStartC, \
                TextInSpan,SpanEnd;
-          SpanStartA = spanKillExp.cap( 1 );
-	  SpanStartB = spanKillExp.cap( 2 );
-	  SpanStartC = spanKillExp.cap( 3 );
-          TextInSpan = spanKillExp.cap( 4 );
-          SpanEnd = spanKillExp.cap( 5 );
-	  kdDebug() << "KBloggerEditor::spanKill A='"<< SpanStartA <<"' B='" <<SpanStartB \
<< "' C='" << SpanStartC << "' Text='" << TextInSpan<< "' SpanEnd='" << SpanEnd \
<<"'"<< endl; +          SpanStartA = richtextToHtmlExp.cap( 1 );
+	  SpanStartB = richtextToHtmlExp.cap( 2 );
+	  SpanStartC = richtextToHtmlExp.cap( 3 );
+          TextInSpan = richtextToHtmlExp.cap( 4 );
+          SpanEnd = richtextToHtmlExp.cap( 5 );
+	  kdDebug() << "KBloggerEditor::richtextToHtml A='"<< SpanStartA <<"' B='" \
<<SpanStartB << "' C='" << SpanStartC << "' Text='" << TextInSpan<< "' SpanEnd='" << \
SpanEnd <<"'"<< endl;  
 	  if (SpanStartB.contains("font-size:16pt;font-weight:600",false)){ //H1
 	    newSpanStart+="<h1>";
@@ -513,11 +517,11 @@
 	    newSpanStart+="<em>";
 	    newSpanEnd="</em>"+newSpanEnd;
 	  }
-	  if (SpanStartB.contains("text-decoration: line-through",false)){
+	  if (SpanStartB.contains(QRegExp("text-decoration:[-\\sa-zA-Z]*line-through[-\\sa-zA-Z]*"))){
  newSpanStart+="<del>";
 	    newSpanEnd="</del>"+newSpanEnd;
 	  }
-	  if (SpanStartB.contains("text-decoration:underline",false)){//underline
+	  if (SpanStartB.contains(QRegExp("text-decoration:[-\\sa-zA-Z]*underline[-\\sa-zA-Z]*"))){//underline
  newSpanStart+="<u>";
 	    newSpanEnd="</u>"+newSpanEnd;
 	  }
@@ -529,11 +533,7 @@
 	    newSpanStart+="<small>";
 	    newSpanEnd="</small>"+newSpanEnd;
 	  }
-	  if (SpanStartB.contains("font-size:6pt",false)){ //small
-	    newSpanStart+="<small>";
-	    newSpanEnd="</small>"+newSpanEnd;
-	  }
-	  if (SpanStartB.contains("font-size:9pt[^;]",false)){ //small
+	  if (SpanStartB.contains(QRegExp("font-size:9pt[^;]?"))){ //small
 	    newSpanStart+="<big>";
 	    newSpanEnd="</big>"+newSpanEnd;
 	  }
@@ -546,10 +546,10 @@
 	    newSpanEnd="</sup>"+newSpanEnd;
 	  }
 
-	  kdDebug() << "KBloggerEditor::spanKill newSpanStart='" << newSpanStart << "' \
                newSpanEnd='" << newSpanEnd <<"'"<<endl;
-	  kdDebug() << "KBloggerEditor::spanKill OldString=" << \
SpanStartA+SpanStartB+SpanStartC+TextInSpan+SpanEnd << "NewString" << \
newSpanStart+TextInSpan+newSpanEnd << endl; +	  kdDebug() << \
"KBloggerEditor::richtextToHtml newSpanStart='" << newSpanStart << "' newSpanEnd='" \
<< newSpanEnd <<"'"<<endl; +	  kdDebug() << "KBloggerEditor::richtextToHtml \
OldString=" << SpanStartA+SpanStartB+SpanStartC+TextInSpan+SpanEnd << "NewString" << \
newSpanStart+TextInSpan+newSpanEnd << endl;  \
dirtyText.replace(SpanStartA+SpanStartB+SpanStartC+TextInSpan+SpanEnd,newSpanStart+TextInSpan+newSpanEnd);
                
-	  kdDebug() << "KBloggerEditor::spanKill dirtyText='"<< dirtyText <<"'"<<endl;
+	  kdDebug() << "KBloggerEditor::richtextToHtml dirtyText='"<< dirtyText \
<<"'"<<endl;  }
 
 	//
@@ -558,20 +558,14 @@
 	return dirtyText;
 }
 
-QString KBloggerEditor::sanitizeText(const QString& text) //FIXME bugs hideout! :)
+QString KBloggerEditor::htmlToRichtext(const QString& text)
 {
-	QString buff;
-	buff=text;
-	
-	buff.remove ( "<html><head><meta name=\"qrichtext\" content=\"1\" /></head>" );
-	buff.remove ( QRegExp ( "<body[^<]+>\n" ) );
-	buff.remove ( QRegExp ("</body></html>" ));
-	//buff.replace( QRegExp ("(<!--StartFragment-->)(<p>)?(<(a |span \
                )[^<]*>)?([^<]*)(</(a|span)>)?(</?.*>)(.*)"),"\\5\\9");
-	buff.remove("<!--StartFragment-->");
-	buff.remove("<!--EndFragment-->");
-	return spanKill(buff);
+	QString dirtyText=text;
+	dirtyText.replace(QRegExp("<del>(.*)</del>"),"<span style=\"text-decoration: \
line-through\">\\1</span>"); +	return dirtyText;
 }
 
+
 void KBloggerEditor::loadPostSlot ( KBlog::BlogPosting& posting )
 {
 	kdDebug() << "KBloggerEditor::loadPostSlot()" << endl;
@@ -665,18 +659,18 @@
  static QWidget *prevPage=VisualPageWidget;
  if (!m_tab){ 
    if (VisualPageWidget-isShown())
-     ContentTextHtmlEditor->setText(sanitizeText(VisualTextEditor->text()));
+     ContentTextHtmlEditor->setText( richtextToHtml(VisualTextEditor->text()) );
  }
 
  if (m_tab == VisualPageWidget && prevPage == HtmlPageWidget) // HTML Editor \
                =>VISUAL editor 
-   VisualTextEditor->setText(ContentTextHtmlEditor->text());
+   VisualTextEditor->setText(htmlToRichtext(ContentTextHtmlEditor->text()));
 
  if (m_tab == HtmlPageWidget && prevPage == VisualPageWidget) // Visual Editor => \
                HTML editor.
-   ContentTextHtmlEditor->setText(spanKill(sanitizeText(VisualTextEditor->text())));
+   ContentTextHtmlEditor->setText(richtextToHtml(VisualTextEditor->text()));
 
  if (m_tab == PreviewPageWidget){ // HTML Editor =>Preview  & Visual Editor => \
Preview  if (prevPage == VisualPageWidget)
-     ContentTextHtmlEditor->setText(sanitizeText(VisualTextEditor->text()));
+     ContentTextHtmlEditor->setText(richtextToHtml(VisualTextEditor->text()));
    writeOnPreview( ContentTextHtmlEditor->text() );
  }
  prevPage=m_tab;
--- trunk/playground/network/kblogger/src/kbloggereditor.h #660692:660693
@@ -76,8 +76,9 @@
 
 	//Functions
 	void insertTag(const QString& textA, const QString& textB=0, const QString& \
                textC=0,tags tag=notags); //Add a richText in the QEditBox at current \
                position.
-	QString spanKill(const QString& text); //convert a <span... in <b, <i, <u....
-	QString sanitizeText(const QString& text); //Remove spellchecking tags, richtext \
tags, convert "richtext to html" +	QString richtextToHtml(const QString& text); \
//convert a <span... in <b, <i, <u.... +	QString htmlToRichtext(const QString& text);
+	//QString sanitizeText(const QString& text); //Remove spellchecking tags, richtext \
tags, convert "richtext to html"  virtual bool close(bool destruct); //Override \
QWidget::Close(bool)  
 private slots:


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

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