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

List:       kde-commits
Subject:    KDE/kdebase/runtime/kioslave/man
From:       Michael Pyne <mpyne () purinchu ! net>
Date:       2008-06-20 0:54:27
Message-ID: 1213923267.882055.16550.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 822391 by mpyne:

Fix HTML output of the kio_man-generated output.

Before: http://purinchu.net/dumping-ground/kio_man_before.jpeg
After:  http://purinchu.net/dumping-ground/kio_man_after.jpeg


 M  +9 -5      kio_man.cpp  
 M  +90 -2     kio_man.css  
 M  +1 -1      kio_man.h  
 M  +56 -37    man2html.cpp  
 M  +12 -3     man2html.h  


--- trunk/KDE/kdebase/runtime/kioslave/man/kio_man.cpp #822390:822391
@@ -135,7 +135,10 @@
     m_cssPath=strPath.toLocal8Bit(); // ### TODO encode for CSS
     section_names << "1" << "2" << "3" << "3n" << "3p" << "4" << "5" << "6" << "7"
                   << "8" << "9" << "l" << "n";
-    m_manCSSFile = KStandardDirs::locate( "data", "kio_man/kio_man.css" );
+
+    QString cssPath(KStandardDirs::locate( "data", "kio_man/kio_man.css" ));
+    KUrl cssUrl(KUrl::fromPath(cssPath));
+    m_manCSSFile = cssUrl.url().toUtf8();
 }
 
 MANProtocol *MANProtocol::self() { return _self; }
@@ -513,6 +516,7 @@
     if (pageFound)
     {
        setResourcePath(m_htmlPath,m_cssPath);
+       setCssFile(m_manCSSFile);
        m_outputBuffer.open(QIODevice::WriteOnly);
        const QByteArray filename=QFile::encodeName(foundPages[0]);
        char *buf = readManPage(filename);
@@ -625,7 +629,7 @@
     os << "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; \
charset=utf-8\">" << endl;  os << "<title>" << i18n("Man output") << "</title>\n" << \
endl;  if ( !m_manCSSFile.isEmpty() )
-        os << "<link href=\"file:///" << m_manCSSFile << "\" type=\"text/css\" \
rel=\"stylesheet\">" << endl; +        os << "<link href=\"" << m_manCSSFile << "\" \
type=\"text/css\" rel=\"stylesheet\">" << endl;  os << "</head>" << endl;
     os << "<body>" << i18n("<h1>KDE Man Viewer Error</h1>") << errmsg << "</body>" \
<< endl;  os << "</html>" << endl;
@@ -643,7 +647,7 @@
     os << "<html>\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; \
charset=utf-8\">"<<endl;  os << "<title>" << i18n("Man output") <<"</title>" << endl;
     if ( !m_manCSSFile.isEmpty() )
-        os << "<link href=\"file:///" << m_manCSSFile << "\" type=\"text/css\" \
rel=\"stylesheet\">" << endl; +        os << "<link href=\"" << m_manCSSFile << "\" \
type=\"text/css\" rel=\"stylesheet\">" << endl;  os << "</head>" <<endl;
     os << "<body><h1>" << i18n("There is more than one matching man page.");
     os << "</h1>\n<ul>\n";
@@ -794,7 +798,7 @@
     os << "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; \
charset=utf-8\">" << endl;  os << "<title>" << i18n("UNIX Manual Index") << \
"</title>" << endl;  if (!m_manCSSFile.isEmpty())
-        os << "<link href=\"file:///" << m_manCSSFile << "\" type=\"text/css\" \
rel=\"stylesheet\">" << endl; +        os << "<link href=\"" << m_manCSSFile << "\" \
type=\"text/css\" rel=\"stylesheet\">" << endl;  os << "</head>" << endl;
     os << "<body><h1>" << i18n("UNIX Manual Index") << "</h1>" << endl;
 
@@ -1224,7 +1228,7 @@
     os << "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; \
charset=utf-8\">" << endl;  os << "<title>" << i18n("UNIX Manual Index") << \
"</title>" << endl;  if ( !m_manCSSFile.isEmpty() )
-        os << "<link href=\"file:///" << m_manCSSFile << "\" type=\"text/css\" \
rel=\"stylesheet\">" << endl; +        os << "<link href=\"" << m_manCSSFile << "\" \
type=\"text/css\" rel=\"stylesheet\">" << endl;  os << "</head>" << endl;
     os << "<body><div class=\"secidxmain\">" << endl;
     os << "<h1>" << i18n( "Index for Section %1: %2", section, sectionName(section)) \
                << "</h1>" << endl;
--- trunk/KDE/kdebase/runtime/kioslave/man/kio_man.css #822390:822391
@@ -1,5 +1,3 @@
-body {background-color:#ffffff;}
-
 /*for the list of one manpage section*/
 .secidxshort {
   display:block;
@@ -19,3 +17,93 @@
 	border-bottom:1px solid black;
 	text-align:center;
 }
+
+/* Stylesheet to use for generated HTML output if we're actually displaying
+ * a man page.
+ * CSS adapted from that used on www.kde.org for similar appearance.
+ */
+body {
+    /* If you specify a background color you should also specify a regular color */
+    background-color: white;
+    color: black;
+    padding: 0px;
+}
+
+#header {
+    width: 100%;
+    color: #535353;
+    background: #eeeeee;
+    border-bottom: #bcbcbc 1px solid;
+}
+
+#header_top {
+    margin: 0 auto;
+    padding: 0;
+    width: 60em;
+    min-width: 770px;
+    max-width: 45em;
+    vertical-align: middle;
+    color: #ffffff;
+    background-repeat: repeat-x;
+    background-position: bottom;
+    background-color: #0057ae;
+}
+
+/*
+ * The header_top div div stuff seems to automatically setup the images but
+ * I'm not sure that it's actually any better than just manually creating a
+ * sequences of non-nested divs and setting an image that way.
+ */
+#header_top div {
+    margin: 0 auto;
+    padding: 0;
+    background-repeat: no-repeat;
+    background-position: bottom left;
+}
+
+#header_top div div {
+    margin: 0 auto;
+    padding: 0;
+    vertical-align: middle;
+    text-align: left;
+    font-size: 1.7em;
+    font-weight: bold;
+    background-repeat: no-repeat;
+    background-position: bottom right;
+}
+
+/*
+ * If the generated HTML does not use an <img> tag in the div div header
+ * sequence then the text will be aligned wrong due to the missing margin
+ * provided by the image.
+ */
+#header_top div div img {
+    margin:8px 0px 9px 18px;
+    vertical-align: middle;
+}
+
+#header_bottom {
+    margin: 0 auto;
+    padding: 0.1em 0em 0.3em 0;
+    width: 60em;
+    min-width: 770px;
+    max-width: 45em;
+    vertical-align: middle;
+    text-align: right;
+    background: #eeeeee;
+}
+
+/* Used for the text and footer area at the bottom. */
+#footer {
+    width: 100%;
+    background-color: #eeeeee;
+    padding-top: 12pt;
+    padding-bottom: 12pt;
+    border-top: #bcbcbc 1px solid;
+    margin-top: 12pt;
+}
+
+#footer_text {
+    text-align:center;
+    vertical-align: middle;
+}
--- trunk/KDE/kdebase/runtime/kioslave/man/kio_man.h #822390:822391
@@ -90,7 +90,7 @@
     QByteArray m_htmlPath; ///< Path to KDE resources, encoded for HTML
     QByteArray m_cssPath; ///< Path to KDE resources, encoded for CSS
     QBuffer m_outputBuffer; ///< Buffer for the output
-    QString m_manCSSFile; ///< Path to kio_man.css
+    QByteArray m_manCSSFile; ///< Path to kio_man.css
 };
 
 
--- trunk/KDE/kdebase/runtime/kioslave/man/man2html.cpp #822390:822391
@@ -154,8 +154,9 @@
 
 
 #if 1
-// The output is current too horrible to be called HTML 4.01
-#define DOCTYPE "<!DOCTYPE HTML>"
+// The output is current too horrible to be called HTML 4.01, so give no
+// DOCTYPE at all.
+#define DOCTYPE ""
 #else
 #define DOCTYPE "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 \
Transitional//EN\">\n"  #endif
@@ -630,7 +631,7 @@
 
 static QList<char*> s_argumentList;
 
-static QByteArray htmlPath, cssPath;
+static QByteArray htmlPath, cssPath, cssFile;
 
 static QByteArray s_dollarZero; // Value of $0
 
@@ -640,6 +641,11 @@
     cssPath=_cssPath;
 }
 
+void setCssFile(const QByteArray& _cssFile)
+{
+    cssFile = _cssFile;
+}
+
 static void fill_old_character_definitions( void )
 {
     for (size_t i = 0; i < sizeof(standardchar)/sizeof(CSTRDEF); i++)
@@ -919,12 +925,18 @@
         }
         break;
     case 0: /* url */
-        g=f=idtest[0];
+        g=f=idtest[0]; // ://foo...
+
+        // backup before :// to get protocol
         while (g>c && isalpha(g[-1]) && islower(g[-1])) g--;
-        h=f+3;
+        h=f+3; // start past ://
+        // determine length of path and part of query it looks like...
         while (*h && !isspace(*h) && *h!='<' && *h!='>' && *h!='"' &&
            *h!='&') h++;
-        if (f-g>2 && f-g<7 && h-f>3) {
+        // if protocol length 3-6 characters and path has any length at all...
+        // more tests added because this code breaks stylesheet links that use
+        // the correct file:/// stuff.
+        if (f-g>2 && f-g<7 && h-f>3 && (strstr(c,"http://") != NULL || \
strstr(c,"ftp://") != NULL) ) {  char t;
         t=*g;
         *g='\0';
@@ -4069,35 +4081,49 @@
                             out_html("<TITLE>");
                                 out_html(scan_troff(wordlist[0], 0, NULL));
                             out_html( " Manpage</TITLE>\n");
+
+                            // KDE defaults.
                             out_html( "<link rel=\"stylesheet\" href=\"");
                             out_html(htmlPath);
                             out_html("/kde-default.css\" type=\"text/css\">\n" );
+
+                            // Output our custom stylesheet.
+                            out_html( "<link rel=\"stylesheet\" href=\"");
+                            out_html(cssFile);
+                            out_html("\" type=\"text/css\">\n" );
+
+                            // Some elements need background images, but this
+                            // could not be included in the stylesheet,
+                            // include it now.
+                            out_html("<style> #header_top { background-image: \
url(\""); +                            out_html(htmlPath);
+                            out_html("/top.jpg\"); } #header_top div"
+                                     " { background-image: url(\"");
+                            out_html(htmlPath);
+                            out_html("/top-left.jpg\"); } #header_top div div "
+                                     "{ background-image: url(\"");
+                            out_html(htmlPath);
+                            out_html("/top-right.jpg\"); }</style>\n\n");
+
                             out_html( "<meta name=\"ROFF Type\" content=\"");
                             if (mandoc_command)
                                 out_html("mdoc");
                             else
                                 out_html("man");
                             out_html("\">\n");
+
                             out_html( "</HEAD>\n\n" );
-                            out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" );
-                            out_html("<div style=\"background-image: url(");
-                            out_html(cssPath);
-                            out_html("/top-middle.png); width: 100%; height: \
                131pt;\">\n" );
-                            out_html("<div style=\"position: absolute; right: \
                0pt;\">\n");
-                            out_html("<img src=\"");
-                            out_html(htmlPath);
-                            out_html("/top-right-konqueror.png\" style=\"margin: \
                0pt\" alt=\"Top right\">\n");
-                            out_html("</div>\n");
+                            out_html("<BODY>\n\n" );
 
-                            out_html("<div style=\"position: absolute; left: \
0pt;\">\n"); +                            out_html("<div id=\"header\"><div \
id=\"header_top\"\n"); +                            out_html("<div><div>\n");
                             out_html("<img src=\"");
                             out_html(htmlPath);
-                            out_html("/top-left.png\" style=\"margin: 0pt\" \
                alt=\"Top left\">\n");
-                            out_html("</div>\n");
-                            out_html("<div style=\"position: absolute; top: 25pt; \
right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: \
#fff 0pt 0pt 5pt; color: #444\">\n"); +                            \
                out_html("/top-kde.jpg\"> ");
                             out_html( scan_troff(wordlist[0], 0, NULL ) );
-                            out_html("</div>\n");
-                            out_html("</div>\n");
+                            out_html(" - KDE Man Page Viewer");
+                            out_html("</div></div></div></div>\n");
+
                             out_html("<div style=\"margin-left: 5em; margin-right: \
5em;\">\n");  out_html("<h1>" );
                                 out_html( scan_troff(wordlist[0], 0, NULL ) );
@@ -5541,27 +5567,20 @@
     out_html(NEWLINE);
 
     if (section) {
-        output_real("<div style=\"margin-left: 2cm\">\n");
+        output_real("</div><div style=\"margin-left: 2cm\">\n");
         section = 0;
     }
 
     if (output_possible) {
-      output_real("</div>\n");
-      output_real("<div class=\"bannerBottom\" style=\"background-image: url(");
-      output_real(cssPath);
-      output_real("/bottom-middle.png); background-repeat: x-repeat; width: 100%; \
                height: 100px; bottom:0pt;\">\n");
-      output_real("<div class=\"bannerBottomLeft\">\n");
-      output_real("<img src=\"");
-      output_real(cssPath);
-      output_real("/bottom-left.png\" style=\"margin: 0pt;\" alt=\"Bottom left of \
                the banner\">\n");
-      output_real("</div>\n");
-      output_real("<div class=\"bannerBottomRight\">\n");
-      output_real("<img src=\"");
-      output_real(cssPath);
-      output_real("/bottom-right.png\" style=\"margin: 0pt\" alt=\"Bottom right of \
                the banner\">\n");
-      output_real("</div>\n");
-      output_real("</div>\n");
+      // The output is buggy wrt to how divs are handled.  Fixing it would
+      // require closing divs before other block-level elements are output,
+      // and I do not feel like going to find them all.
+      output_real("</div></div></div></div>\n");
 
+      output_real("<div id=\"footer\"><div id=\"footer_text\">\n");
+      output_real("Generated by kio_man, KDE version " KDE_VERSION_STRING);
+      output_real("</div></div>\n\n");
+
       output_real("</BODY>\n</HTML>\n");
     }
     delete [] buf;
--- trunk/KDE/kdebase/runtime/kioslave/man/man2html.h #822390:822391
@@ -1,9 +1,9 @@
 /**
  * \file man2html.h
  *
- * \note Despite that this file is installed publically, it should not be included
- * \todo ### KDE4: make this file private
- *
+ * Converts man pages to HTML.  This kioslave is not part of kdelibs and is
+ * not public API.
+ * \internal
  */
 
 #ifndef MAN2HTML_H
@@ -24,6 +24,15 @@
  */
 extern void setResourcePath(const QByteArray& _htmlPath, const QByteArray& \
_cssPath);  
+/*
+ * Sets the path to a CSS file that should be included with the generated
+ * HTML output.
+ *
+ * \param HTML-encoded path to the file to reference for stylesheets.
+ * \since 4.1
+ */
+extern void setCssFile(const QByteArray& _cssFile);
+
 /** implement this somewhere. It will be called
    with HTML contents
 */


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

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