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

List:       kde-commits
Subject:    kdeextragear-2/konversation/konversation
From:       John Tapsell <john () geola ! co ! uk>
Date:       2004-12-31 22:50:59
Message-ID: 20041231225059.68FF91CD50 () office ! kde ! org
[Download RAW message or body]

CVS commit by johnflux: 

Make the pasting of html a bit nicer.


  M +27 -16    ircinput.cpp   1.59


--- kdeextragear-2/konversation/konversation/ircinput.cpp  #1.58:1.59
@@ -259,5 +259,9 @@ void IRCInput::insertHtml(const QString&
 {
   QString text(htmlTextToInsert);
-  // replace \r with \n to make xterm pastes happy
+   //We will treat \n as a \n in the paste, despite it usually being ignored
+  //This is so <pre> etc work fine.  It's works fairly well, as this is only for pasting
+  //a few lines, and those few lines will probably not have many arbituary \n's in it.
+  
+// replace \r with \n to make xterm pastes happy
   text.replace("\r","\n");
   text.replace("<p>","\n", false);
@@ -276,29 +280,33 @@ void IRCInput::insertHtml(const QString&
   text.replace("</u>","%U", false);
 
-  text.replace(QRegExp("<font [^>]*color *= *[\"']black[^>]*>", false), "%C1");
-  text.replace(QRegExp("<font [^>]*color *= *[\"']#000000[^>]*>", false), "%C1");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']black[^>]*>", false), "%C1");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']#000000[^>]*>", false), "%C1");
   
-  text.replace(QRegExp("<font [^>]*color *= *[\"']orange[^>]*>", false), "%C7");
-  text.replace(QRegExp("<font [^>]*color *= *[\"']#ffa500[^>]*>", false), "%C7");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']orange[^>]*>", false), "%C7");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']#ffa500[^>]*>", false), "%C7");
   
-  text.replace(QRegExp("<font [^>]*color *= *[\"']pink[^>]*>", false), "%C13");
-  text.replace(QRegExp("<font [^>]*color *= *[\"']#ffc0cb[^>]*>", false), "%C13");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']pink[^>]*>", false), "%C13");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']#ffc0cb[^>]*>", false), "%C13");
  
-  text.replace(QRegExp("<font [^>]*color *= *[\"']aqua[^>]*>", false), "%C12");
-  text.replace(QRegExp("<font [^>]*color *= *[\"']#00ffff[^>]*>", false), "%C12");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']aqua[^>]*>", false), "%C12");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']#00ffff[^>]*>", false), "%C12");
   
-  text.replace(QRegExp("<font [^>]*color *= *[\"']red[^>]*>", false), "%C4");
-  text.replace(QRegExp("<font [^>]*color *= *[\"']#ff0000[^>]*>", false), "%C4");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']red[^>]*>", false), "%C4");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']#ff0000[^>]*>", false), "%C4");
   
-  text.replace(QRegExp("<font [^>]*color *= *[\"']green[^>]*>", false), "%C9");
-  text.replace(QRegExp("<font [^>]*color *= *[\"']#00ff00[^>]*>", false), "%C9");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']green[^>]*>", false), "%C9");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']#00ff00[^>]*>", false), "%C9");
   
-  text.replace(QRegExp("<font [^>]*color *= *[\"']blue[^>]*>", false), "%C2");
-  text.replace(QRegExp("<font [^>]*color *= *[\"']#0000ff[^>]*>", false), "%C2");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']blue[^>]*>", false), "%C2");
+  text.replace(QRegExp("< *font [^>]*color *= *[\"']#0000ff[^>]*>", false), "%C2");
   
   text.replace(QRegExp("</ *font *>",false), "%C1");
   
+  //get rid of anything else not recognised
   text.replace(QRegExp("<[^>]*>"), "");
 
+  //strip multiple empty newlines
+  text.replace(QRegExp("\n[ <t]*\n"), "");
+  
 
   text.replace("&amp;", "&");
@@ -306,4 +314,7 @@ void IRCInput::insertHtml(const QString&
   text.replace("&gt;", ">");
 
+  //strip newlines at the start and end.
+  text = text.stripWhiteSpace();
+  
   // is there a newline in the pasted/inserted text?
   if(text.find('\n')!=-1)


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

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