[gtk-doc] db2html: add basic recursive block converter



commit 989a30526dd8d1bb44d42c269e78ad5b5eb55612
Author: Stefan Sauer <ensonic users sf net>
Date:   Wed Jan 10 21:18:10 2018 +0100

    db2html: add basic recursive block converter
    
    We'll call this for content blocks with the local xml subtrees.
    
    Try it for the books 'releaseinfo'.

 tools/db2html.py           |   47 +++++++++++++++++++++++++++++++++++++++++--
 tools/templates/book.html  |   10 ++++----
 tools/templates/index.html |    2 +-
 3 files changed, 50 insertions(+), 9 deletions(-)
---
diff --git a/tools/db2html.py b/tools/db2html.py
index c1a3e33..ab485d2 100644
--- a/tools/db2html.py
+++ b/tools/db2html.py
@@ -30,7 +30,12 @@ TODO: convert the docbook-xml to html
 - for refsect, we need a 'long-title' that also contains refpurpose
 - figure how to deal with all the possible docbook
   - how can we report 'unhandled' data
-- we need a generic transform for everything in a para
+- we need a generic transform for everything in a para (and others like
+  releaseinfo)
+  - this will walk the tree and replace nodes to convert from docbook to html
+  - we can start with 1:1, but most likely each transform will be a function
+    that mangles the sub tree and recurses for certain children (kind of what
+    xslt does)
 
 OPTIONAL:
 - minify html: https://pypi.python.org/pypi/htmlmin/
@@ -183,6 +188,43 @@ def chunk(xml_node, parent=None):
     return parent
 
 
+def convert__inner(xml):
+    result = ''
+    for child in xml:
+        result += convert_tags.get(child.tag)(child)
+    return result
+
+
+def convert__unknown(xml):
+    logging.warning('Add tag converter for "%s"', xml.tag)
+    return '<!-- ' + xml.tag + '-->\n'
+
+
+def convert_para(xml):
+    result = '<p>'
+    if xml.tag != 'para':
+        result = '<p class="%s">' % xml.tag
+    if xml.text:
+        result += xml.text
+    result += convert__inner(xml)
+    result += '\n</p>'
+    if xml.tail:
+        result += xml.tail
+    return result
+
+
+def convert_ulink(xml):
+    url = xml.text
+    result = '<a class="%s" href="%s">%s</a>' % (xml.tag, url, url)
+    return result
+
+
+convert_tags = {
+    'para': convert_para,
+    'ulink': convert_ulink,
+}
+
+
 def convert(out_dir, files, node):
     """Convert the docbook chunks to a html file."""
 
@@ -200,8 +242,7 @@ def convert(out_dir, files, node):
             #     return xml.xpath(expr)
 
             template = TEMPLATES[node.name]
-            # template.globals['xpath'] = lxml_xpath
-            # template.globals['xpath_str0'] = lxml_xpath_str0
+            template.globals['convert_para'] = convert_para
             params = {
                 'xml': node.xml,
                 'title': node.title,
diff --git a/tools/templates/book.html b/tools/templates/book.html
index 8546bb2..a38a361 100644
--- a/tools/templates/book.html
+++ b/tools/templates/book.html
@@ -7,14 +7,14 @@
 {{ head_links(nav_home, nav_up, nav_prev, nav_next) }}
 <link rel="stylesheet" href="style.css" type="text/css">
 </head>
-<body>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
 <div class="book">
 <div class="titlepage">
 {{ navigation_main(title) }}
-{% set releaseinfo=xml.find('bookinfo/releaseinfo') %}
-{% if releaseinfo %}
-{{ releaseinfo.text }}
-{% endif %}
+{%- set releaseinfo=xml.find('bookinfo/releaseinfo') %}
+{%- if releaseinfo %}
+{{ convert_para(releaseinfo) }}
+{%- endif %}
 <hr>
 </div>
 <div class="toc">
diff --git a/tools/templates/index.html b/tools/templates/index.html
index 834a3d4..831a3c3 100644
--- a/tools/templates/index.html
+++ b/tools/templates/index.html
@@ -7,7 +7,7 @@
 {{ head_links(nav_home, nav_up, nav_prev, nav_next) }}
 <link rel="stylesheet" href="style.css" type="text/css">
 </head>
-<body>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
 {{ navigation_idx(nav_home, nav_up, nav_prev, nav_next) }}
 <div class="index">
 <div class="titlepage"><h1 class="title"><a name="api-index"></a>{{ title }}</h1></div>


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