Sfoglia il codice sorgente

write toc for manuals

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@59673 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 anni fa
parent
commit
bf277102ed
3 ha cambiato i file con 75 aggiunte e 7 eliminazioni
  1. 18 1
      man/grassdocs.css
  2. 1 3
      raster/r.in.gdal/r.in.gdal.html
  3. 56 3
      tools/mkhtml.py

+ 18 - 1
man/grassdocs.css

@@ -14,6 +14,7 @@ body{
     background: white;
     background: white;
     color: black;
     color: black;
     font-family: arial,sans-serif;
     font-family: arial,sans-serif;
+    width: 80%;
 }
 }
 
 
 h1{
 h1{
@@ -49,7 +50,7 @@ h4{
 }
 }
 
 
 div.code{
 div.code{
-    width: 95%;
+    width: 100%;
     color : black;
     color : black;
     background-color: rgb(90%, 90%, 90%);
     background-color: rgb(90%, 90%, 90%);
     padding-left: 1em;
     padding-left: 1em;
@@ -86,3 +87,19 @@ table.border td {
 td {
 td {
     padding: 5px;
     padding: 5px;
 }
 }
+
+table.toc{
+    background-color: transparent;
+    position: fixed;
+    border: solid 1px rgb(25%, 60%, 25%);
+    top: 5px;
+    right: 5px;
+    width: 17%;
+    font-weight: bold;
+    font-family: arial,sans-serif;
+}
+
+a.toc {
+    color: rgb(25%, 60%, 25%);
+    text-decoration: none;
+}

+ 1 - 3
raster/r.in.gdal/r.in.gdal.html

@@ -4,12 +4,10 @@
 or imagery group, from any GDAL supported raster map format, with an optional 
 or imagery group, from any GDAL supported raster map format, with an optional 
 title. The imported file may also be optionally used to create a new location.
 title. The imported file may also be optionally used to create a new location.
 
 
-<!--<h2>OPTIONS</h2>
+<!--
 
 
 Extended explanations:
 Extended explanations:
 
 
-<h3>Flags:</h3>
-
 <dt><b>-e</b>
 <dt><b>-e</b>
 <dd>Extend the DEFAULT_WIND in PERMANENT mapset to include the region of
 <dd>Extend the DEFAULT_WIND in PERMANENT mapset to include the region of
 the new map layer.  Old resolution is preserved, but the region, and rows/cols
 the new map layer.  Old resolution is preserved, but the region, and rows/cols

+ 56 - 3
tools/mkhtml.py

@@ -2,12 +2,12 @@
 
 
 ############################################################################
 ############################################################################
 #
 #
-# MODULE:       mkhtml.py
+# MODULE:       Builds manual pages
 # AUTHOR(S):    Markus Neteler
 # AUTHOR(S):    Markus Neteler
 #               Glynn Clements
 #               Glynn Clements
 #               Martin Landa <landa.martin gmail.com>
 #               Martin Landa <landa.martin gmail.com>
 # PURPOSE:      Create HTML manual page snippets
 # PURPOSE:      Create HTML manual page snippets
-# COPYRIGHT:    (C) 2007, 2009, 2011-2012 by Glynn Clements
+# COPYRIGHT:    (C) 2007-2014 by Glynn Clements
 #                and the GRASS Development Team
 #                and the GRASS Development Team
 #
 #
 #               This program is free software under the GNU General
 #               This program is free software under the GNU General
@@ -21,6 +21,7 @@ import os
 import string
 import string
 import re
 import re
 from datetime import datetime
 from datetime import datetime
+from HTMLParser import HTMLParser
 
 
 pgm = sys.argv[1]
 pgm = sys.argv[1]
 
 
@@ -70,6 +71,53 @@ def read_file(name):
     except IOError:
     except IOError:
         return ""
         return ""
 
 
+def create_toc(src_data):
+    class MyHTMLParser(HTMLParser):
+        def __init__(self):
+            self.reset()
+            self.idx = 1
+            self.tag = ''
+            self.data = []
+            
+        def handle_starttag(self, tag, attrs):
+            self.tag = tag
+
+        def handle_endtag(self, tag):
+            self.tag = ''
+        
+        def handle_data(self, data):
+            if self.tag in ('h1', 'h2', 'h3'):
+                self.data.append((self.tag, '%s_%d' % (self.tag, self.idx), data))
+                self.idx += 1
+
+    # instantiate the parser and fed it some HTML
+    parser = MyHTMLParser()
+    parser.feed(src_data)
+    
+    return parser.data
+
+def write_toc(data):
+    fd = sys.stdout
+    fd.write('<table class="toc">\n')
+    for tag, href, text in data:
+        fd.write('<tr><td>%s <a href="#%s" class="toc">%s</a></td></tr>\n' % \
+                     ('&nbsp;&nbsp;' if tag == 'h3' else '', href, text))
+    fd.write('</table>\n')
+
+def update_toc(data):
+    ret_data = []
+    pat = re.compile(r'(<(h\d)>)(.+)(</h\d>)')
+    idx = 1
+    for line in data.splitlines():
+        if pat.search(line):
+            xline = pat.split(line)
+            line = xline[1] + '<a name="%s_%d">' % (xline[2], idx) + xline[3] + '</a>' + xline[4]
+            idx += 1
+        ret_data.append(line)
+    
+    return '\n'.join(ret_data)
+
+# process header
 src_data = read_file(src_file)
 src_data = read_file(src_file)
 name = re.search('(<!-- meta page name:)(.*)(-->)', src_data, re.IGNORECASE)
 name = re.search('(<!-- meta page name:)(.*)(-->)', src_data, re.IGNORECASE)
 if name:
 if name:
@@ -90,7 +138,11 @@ if not re.search('<html>', src_data, re.IGNORECASE):
             if not re.search('</body>|</html>', line, re.IGNORECASE):
             if not re.search('</body>|</html>', line, re.IGNORECASE):
                 sys.stdout.write(line)
                 sys.stdout.write(line)
 
 
-sys.stdout.write(src_data)
+# create TOC
+write_toc(create_toc(src_data))
+
+# process body
+sys.stdout.write(update_toc(src_data))
 
 
 # if </html> is found, suppose a complete html is provided.
 # if </html> is found, suppose a complete html is provided.
 # otherwise, generate module class reference:
 # otherwise, generate module class reference:
@@ -112,6 +164,7 @@ index_names = {
     'v' : 'vector'
     'v' : 'vector'
     }
     }
 
 
+# process footer
 index = re.search('(<!-- meta page index:)(.*)(-->)', src_data, re.IGNORECASE)
 index = re.search('(<!-- meta page index:)(.*)(-->)', src_data, re.IGNORECASE)
 if index:
 if index:
     index_name_cap = index_name = index.group(2).strip()
     index_name_cap = index_name = index.group(2).strip()