[GRASS-SVN] r59685 - in grass/trunk: man tools
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Apr 11 03:33:22 PDT 2014
Author: lucadelu
Date: 2014-04-11 03:33:21 -0700 (Fri, 11 Apr 2014)
New Revision: 59685
Modified:
grass/trunk/man/grassdocs.css
grass/trunk/tools/mkhtml.py
Log:
mkhtml.py: add ul-li to toc, PEP8 cleanup
Modified: grass/trunk/man/grassdocs.css
===================================================================
--- grass/trunk/man/grassdocs.css 2014-04-11 10:11:51 UTC (rev 59684)
+++ grass/trunk/man/grassdocs.css 2014-04-11 10:33:21 UTC (rev 59685)
@@ -95,12 +95,16 @@
top: 5px;
right: 5px;
width: 17%;
- line-height: 110%;
+ line-height: 120%;
font-weight: bold;
font-size: small;
font-family: arial,sans-serif;
}
+ul.toc li.toc {
+ margin-left:-25px;
+}
+
a.toc {
color: rgb(25%, 60%, 25%);
text-decoration: none;
Modified: grass/trunk/tools/mkhtml.py
===================================================================
--- grass/trunk/tools/mkhtml.py 2014-04-11 10:11:51 UTC (rev 59684)
+++ grass/trunk/tools/mkhtml.py 2014-04-11 10:33:21 UTC (rev 59685)
@@ -62,6 +62,7 @@
</html>
""")
+
def read_file(name):
try:
f = open(name, 'rb')
@@ -71,6 +72,7 @@
except IOError:
return ""
+
def create_toc(src_data):
class MyHTMLParser(HTMLParser):
def __init__(self):
@@ -78,32 +80,46 @@
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.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')
+ ul = False
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))
+ if tag == 'h3':
+ if not ul:
+ fd.write('<tr><td><ul class="toc">\n')
+ ul = True
+ fd.write('<li class="toc"><a href="#%s" class="toc">%s</a></li>\n' % \
+ (href, text))
+ else:
+ if ul:
+ fd.write('</ul></td></tr>\n')
+ ul = False
+ fd.write('<tr><td> <a href="#%s" class="toc">%s</a></td></tr>\n' % \
+ (href, text))
fd.write('</table>\n')
+
def update_toc(data):
ret_data = []
pat = re.compile(r'(<(h\d)>)(.+)(</h\d>)')
@@ -114,7 +130,7 @@
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
@@ -122,7 +138,8 @@
name = re.search('(<!-- meta page name:)(.*)(-->)', src_data, re.IGNORECASE)
if name:
pgm = name.group(2).strip().split('-', 1)[0].strip()
-desc = re.search('(<!-- meta page description:)(.*)(-->)', src_data, re.IGNORECASE)
+desc = re.search('(<!-- meta page description:)(.*)(-->)', src_data,
+ re.IGNORECASE)
if desc:
pgm = desc.group(2).strip()
header_tmpl = string.Template(header_base + header_nopgm)
@@ -132,7 +149,7 @@
if not re.search('<html>', src_data, re.IGNORECASE):
tmp_data = read_file(tmp_file)
if not re.search('<html>', tmp_data, re.IGNORECASE):
- sys.stdout.write(header_tmpl.substitute(PGM = pgm))
+ sys.stdout.write(header_tmpl.substitute(PGM=pgm))
if tmp_data:
for line in tmp_data.splitlines(True):
if not re.search('</body>|</html>', line, re.IGNORECASE):
@@ -173,13 +190,16 @@
index_name = index_names.get(mod_class, '')
index_name_cap = index_name.title()
-grass_version = os.getenv("VERSION_NUMBER", "unknown")
+grass_version = os.getenv("VERSION_NUMBER", "unknown")
year = os.getenv("VERSION_DATE")
if not year:
year = str(datetime.now().year)
if index_name:
- sys.stdout.write(footer_index.substitute(INDEXNAME = index_name, INDEXNAMECAP = index_name_cap,
- YEAR = year, GRASS_VERSION = grass_version))
+ sys.stdout.write(footer_index.substitute(INDEXNAME=index_name,
+ INDEXNAMECAP=index_name_cap,
+ YEAR=year,
+ GRASS_VERSION=grass_version))
else:
- sys.stdout.write(footer_noindex.substitute(YEAR = year, GRASS_VERSION = grass_version))
+ sys.stdout.write(footer_noindex.substitute(YEAR=year,
+ GRASS_VERSION=grass_version))
More information about the grass-commit
mailing list