[yelp] Do the indents in man pages correctly with CSS and javascript.



commit a61c5626b27be4c0e3b616f615e46540a32e96a0
Author: Rupert Swarbrick <rswarbrick gmail com>
Date:   Mon Jan 3 21:00:08 2011 +0000

    Do the indents in man pages correctly with CSS and javascript.

 libyelp/yelp-man-parser.c   |    6 +++-
 stylesheets/man2html.xsl.in |   45 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/libyelp/yelp-man-parser.c b/libyelp/yelp-man-parser.c
index 35079d0..e8d28b2 100644
--- a/libyelp/yelp-man-parser.c
+++ b/libyelp/yelp-man-parser.c
@@ -976,8 +976,6 @@ deal_with_newlines (YelpManParser *parser)
     }
 
     if (parser->newline) {
-        append_nbsps (parser, dx_to_em_count (parser, parser->hpos));
-
         if ((parser->last_vertical_jump > 0) && (!dont_jump)) {
             jump_lines =
                 parser->last_vertical_jump/parser->char_height;
@@ -990,6 +988,10 @@ deal_with_newlines (YelpManParser *parser)
             made_sheet = TRUE;
         }
 
+        snprintf (tmp, 64, "%u", dx_to_em_count (parser, parser->hpos));
+        xmlNewProp (parser->sheet_node,
+                    BAD_CAST "indent", BAD_CAST tmp);
+
         if (made_sheet) {
             snprintf (tmp, 64, "%u", jump_lines-1);
             xmlNewProp (parser->sheet_node,
diff --git a/stylesheets/man2html.xsl.in b/stylesheets/man2html.xsl.in
index 8785195..a9907b9 100644
--- a/stylesheets/man2html.xsl.in
+++ b/stylesheets/man2html.xsl.in
@@ -21,6 +21,18 @@
 </xsl:template>
 
 <xsl:template mode="html.body.mode" match="Man">
+  <!-- Invisible div that we use to calculate the indent width. -->
+  <xsl:element name="div">
+    <xsl:attribute name="id">invisible-char</xsl:attribute>
+    <xsl:attribute name="style">
+      position: absolute;
+      font-family: monospace;
+      visibility: hidden;
+      height: auto;
+      width: auto;
+    </xsl:attribute>
+    <xsl:text>X</xsl:text>
+  </xsl:element>
   <xsl:apply-templates select="header"/>
   <xsl:apply-templates select="section"/>
 </xsl:template>
@@ -73,7 +85,9 @@
     <xsl:attribute name="style">
       margin-bottom: 0px;
       margin-top: <xsl:value-of select="@jump"/>em;
+      margin-left: <xsl:value-of select="@indent"/>ex;
     </xsl:attribute>
+    <xsl:attribute name="class">sheet</xsl:attribute>
     <p><xsl:apply-templates select="span|br|a"/></p>
   </xsl:element>
 </xsl:template>
@@ -107,4 +121,35 @@
   </xsl:element>
 </xsl:template>
 
+<xsl:template name="html.head.custom">
+<!--
+  The following javascript function fixes up the indent of sheets
+  correctly. The indent should be some number of character widths, but
+  you can't do that in CSS, so we have something like "7ex" as a
+  stand-in (but ex is too thin here). There's an invisible div with
+  the correct styling and a single character which we measure the
+  width of and update each sheet as required.
+-->
+<script type="text/javascript" language="javascript">
+<xsl:text>
+$(document).ready (function () {
+  var div = document.getElementById("invisible-char");
+  var width = div.clientWidth;
+
+  var all_divs = document.getElementsByTagName("div");
+  for (var i=0; i &lt; all_divs.length; i++) {
+    var elt = all_divs[i];
+    if (elt.getAttribute("class") == "sheet") {
+      var indent_str = elt.style.marginLeft;
+      var indent = indent_str.substr (0, indent_str.length - 2);
+
+      elt.style.marginLeft = width * indent + "px";
+    }
+  }
+});
+</xsl:text>
+</script>
+</xsl:template>
+
+
 </xsl:stylesheet>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]