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

List:       kwrite-devel
Subject:    [Bug 109932] Export to HTML generates ill-formed XHTML for javadoc
From:       Anders Lund <anders () alweb ! dk>
Date:       2005-11-01 22:49:26
Message-ID: 20051101224926.10713.qmail () ktown ! kde ! org
[Download RAW message or body]

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=109932         
anders alweb dk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From anders alweb dk  2005-11-01 23:49 -------
SVN commit 476751 by alund:

HTML export enhancements: No more B and I tags, only SPAN with inline CSS.
The returned HTML text is between 2-5 times as big, but this is much more correct (no \
more b0rk3d HTML) and supports ALL the attributes we currently use: color, bgcolor, \
bold, italic, underline, overline, strike-out, as opposed to the B, I and color \
attribs supported before. BUG:109932 


 M  +53 -74    kateview.cpp  


--- branches/KDE/3.5/kdelibs/kate/part/kateview.cpp #476750:476751
 @ -1706,93 +1706,72  @
   (*ts) << "</pre>";
 }
 
+// fully rewritten to use only inline CSS and support all used attribs.
+// anders, 2005-11-01 23:39:43
 void KateView::lineAsHTML (KateTextLine::Ptr line, uint startCol, uint length, \
QTextStream *outputStream)  {
-  if(length == 0) return;
-  // some variables :
-  bool previousCharacterWasBold = false;
-  bool previousCharacterWasItalic = false;
-  // when entering a new color, we'll close all the <b> & <i> tags,
-  // for HTML compliancy. that means right after that font tag, we'll
-  // need to reinitialize the <b> and <i> tags.
-  bool needToReinitializeTags = false;
-  QColor previousCharacterColor(0,0,0); // default color of HTML characters is black
-  QColor blackColor(0,0,0);
-//  (*outputStream) << "<span style='color: #000000'>";
+  if(length == 0)
+    return;
 
+  // do not recalculate the style strings again and again
+  QMap<uchar,QString> stylecache;
+  // do not insert equally styled characters one by one
+  QString textcache;
 
-  // for each character of the line : (curPos is the position in the line)
+  KateAttribute *charAttributes = 0;
+
   for (uint curPos=startCol;curPos<(length+startCol);curPos++)
+  {
+    if ( curPos == 0 || line->attribute( curPos ) != line->attribute( curPos - 1 ) \
&& +         KateAttribute(*charAttributes) != \
KateAttribute(*m_renderer->attribute(line->attribute(curPos))) )  {
-      KateAttribute* charAttributes = 0;
+      (*outputStream) << textcache;
+      textcache.truncate(0);
 
+      if ( curPos > startCol )
+        (*outputStream) << "</span>";
+
       charAttributes = m_renderer->attribute(line->attribute(curPos));
 
-      //ASSERT(charAttributes != NULL);
-      // let's give the color for that character :
-      if ( (charAttributes->textColor() != previousCharacterColor))
-      {  // the new character has a different color :
-        // if we were in a bold or italic section, close it
-        if (previousCharacterWasBold)
-          (*outputStream) << "</b>";
-        if (previousCharacterWasItalic)
-          (*outputStream) << "</i>";
+      if ( ! stylecache.contains( line->attribute(curPos) ) )
+      {
+        QString textdecoration;
+        QString style;
 
-        // close the previous font tag :
-  if(previousCharacterColor != blackColor)
-          (*outputStream) << "</span>";
-        // let's read that color :
-        int red, green, blue;
-        // getting the red, green, blue values of the color :
-        charAttributes->textColor().rgb(&red, &green, &blue);
-  if(!(red == 0 && green == 0 && blue == 0)) {
-          (*outputStream) << "<span style='color: #"
-              << ( (red < 0x10)?"0":"")  // need to put 0f, NOT f for instance. \
                don't touch 1f.
-              << QString::number(red, 16) // html wants the hex value here (hence \
                the 16)
-              << ( (green < 0x10)?"0":"")
-              << QString::number(green, 16)
-              << ( (blue < 0x10)?"0":"")
-              << QString::number(blue, 16)
-              << "'>";
-  }
-        // we need to reinitialize the bold/italic status, since we closed all the \
                tags
-        needToReinitializeTags = true;
-      }
-      // bold status :
-      if ( (needToReinitializeTags && charAttributes->bold()) ||
-          (!previousCharacterWasBold && charAttributes->bold()) )
-        // we enter a bold section
-        (*outputStream) << "<b>";
-      if ( !needToReinitializeTags && (previousCharacterWasBold && \
                !charAttributes->bold()) )
-        // we leave a bold section
-        (*outputStream) << "</b>";
+        if ( charAttributes->bold() )
+          style.append("font-weight: bold;");
+        if ( charAttributes->italic() )
+          style.append("text-style: italic;");
+        if ( charAttributes->underline() )
+          textdecoration = "underline";
+        if ( charAttributes->overline() )
+          textdecoration.append(" overline" );
+        if ( charAttributes->strikeOut() )
+          textdecoration.append(" line-trough" );
+        if ( !textdecoration.isEmpty() )
+          style.append("text-decoration: %1;").arg(textdecoration);
+        // QColor::name() returns a string in the form "#RRGGBB" in Qt 3.
+        // NOTE Qt 4 returns "#AARRGGBB"
+        if ( charAttributes->itemSet(KateAttribute::BGColor) )
+          style.append(QString("background-color: \
%1;").arg(charAttributes->bgColor().name())); +        if ( \
charAttributes->itemSet(KateAttribute::TextColor) ) +          \
style.append(QString("color: %1;").arg(charAttributes->textColor().name()));  
-      // italic status :
-      if ( (needToReinitializeTags && charAttributes->italic()) ||
-           (!previousCharacterWasItalic && charAttributes->italic()) )
-        // we enter an italic section
-        (*outputStream) << "<i>";
-      if ( !needToReinitializeTags && (previousCharacterWasItalic && \
                !charAttributes->italic()) )
-        // we leave an italic section
-        (*outputStream) << "</i>";
-
-      // write the actual character :
-      (*outputStream) << QStyleSheet::escape(QString(line->getChar(curPos)));
-
-      // save status for the next character :
-      previousCharacterWasItalic = charAttributes->italic();
-      previousCharacterWasBold = charAttributes->bold();
-      previousCharacterColor = charAttributes->textColor();
-      needToReinitializeTags = false;
+        stylecache[line->attribute(curPos)] = style;
+      }
+      (*outputStream)<<"<span style=\""
+          << stylecache[line->attribute(curPos)]
+          << "\">";
     }
-  // Be good citizens and close our tags
-  if (previousCharacterWasBold)
-    (*outputStream) << "</b>";
-  if (previousCharacterWasItalic)
-    (*outputStream) << "</i>";
 
-  if(previousCharacterColor != blackColor)
-    (*outputStream) << "</span>";
+    QString s( line->getChar(curPos) );
+    if ( s == "&" ) s = "&amp;";
+    else if ( s == "<" ) s = "&lt;";
+    else if ( s == ">" ) s = "&gt;";
+    textcache.append( s );
+  }
+
+  (*outputStream) << textcache << "</span>";
 }
 
 void KateView::exportAsHTML ()
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel


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

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