[GRASS-SVN] r59673 - in grass/trunk: man raster/r.in.gdal tools
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Apr 10 11:09:49 PDT 2014
Author: martinl
Date: 2014-04-10 11:09:48 -0700 (Thu, 10 Apr 2014)
New Revision: 59673
Modified:
grass/trunk/man/grassdocs.css
grass/trunk/raster/r.in.gdal/r.in.gdal.html
grass/trunk/tools/mkhtml.py
Log:
write toc for manuals
Modified: grass/trunk/man/grassdocs.css
===================================================================
--- grass/trunk/man/grassdocs.css 2014-04-10 17:31:53 UTC (rev 59672)
+++ grass/trunk/man/grassdocs.css 2014-04-10 18:09:48 UTC (rev 59673)
@@ -14,6 +14,7 @@
background: white;
color: black;
font-family: arial,sans-serif;
+ width: 80%;
}
h1{
@@ -49,7 +50,7 @@
}
div.code{
- width: 95%;
+ width: 100%;
color : black;
background-color: rgb(90%, 90%, 90%);
padding-left: 1em;
@@ -86,3 +87,19 @@
td {
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;
+}
Modified: grass/trunk/raster/r.in.gdal/r.in.gdal.html
===================================================================
--- grass/trunk/raster/r.in.gdal/r.in.gdal.html 2014-04-10 17:31:53 UTC (rev 59672)
+++ grass/trunk/raster/r.in.gdal/r.in.gdal.html 2014-04-10 18:09:48 UTC (rev 59673)
@@ -4,12 +4,10 @@
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.
-<!--<h2>OPTIONS</h2>
+<!--
Extended explanations:
-<h3>Flags:</h3>
-
<dt><b>-e</b>
<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
Modified: grass/trunk/tools/mkhtml.py
===================================================================
--- grass/trunk/tools/mkhtml.py 2014-04-10 17:31:53 UTC (rev 59672)
+++ grass/trunk/tools/mkhtml.py 2014-04-10 18:09:48 UTC (rev 59673)
@@ -2,12 +2,12 @@
############################################################################
#
-# MODULE: mkhtml.py
+# MODULE: Builds manual pages
# AUTHOR(S): Markus Neteler
# Glynn Clements
# Martin Landa <landa.martin gmail.com>
# 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
#
# This program is free software under the GNU General
@@ -21,6 +21,7 @@
import string
import re
from datetime import datetime
+from HTMLParser import HTMLParser
pgm = sys.argv[1]
@@ -70,6 +71,53 @@
except IOError:
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' % \
+ (' ' 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)
name = re.search('(<!-- meta page name:)(.*)(-->)', src_data, re.IGNORECASE)
if name:
@@ -90,8 +138,12 @@
if not re.search('</body>|</html>', line, re.IGNORECASE):
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.
# otherwise, generate module class reference:
if re.search('</html>', src_data, re.IGNORECASE):
@@ -112,6 +164,7 @@
'v' : 'vector'
}
+# process footer
index = re.search('(<!-- meta page index:)(.*)(-->)', src_data, re.IGNORECASE)
if index:
index_name_cap = index_name = index.group(2).strip()
More information about the grass-commit
mailing list