[Epydoc-commits] SF.net SVN: epydoc: [1780] trunk/epydoc/src/tools/sty2html.py
Brought to you by:
edloper
From: <ed...@us...> - 2008-02-24 06:49:21
|
Revision: 1780 http://epydoc.svn.sourceforge.net/epydoc/?rev=1780&view=rev Author: edloper Date: 2008-02-23 22:49:16 -0800 (Sat, 23 Feb 2008) Log Message: ----------- - Syntax highlighting for sty files Added Paths: ----------- trunk/epydoc/src/tools/sty2html.py Added: trunk/epydoc/src/tools/sty2html.py =================================================================== --- trunk/epydoc/src/tools/sty2html.py (rev 0) +++ trunk/epydoc/src/tools/sty2html.py 2008-02-24 06:49:16 UTC (rev 1780) @@ -0,0 +1,115 @@ +#!/usr/bin/env python +# +# Convert epydoc's LaTeX sty files to HTML + +from epydoc.docwriter.latex_sty import STYLESHEETS +import re, sys, os.path + +TEMPLATE = """\ +<?xml version="1.0" encoding="ascii" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ascii" /> +<title>%(title)s</title> +<link rel="stylesheet" href="epydoc.css" type="text/css" /> +</head> +<body> +<div class="body"> +<h1 class="title">%(title)s</h1> +<pre>%(body)s</pre> +</div> +<table width="100%%" class="navbox" cellpadding="1" cellspacing="0"> + <tr> + <a class="nav" href="index.html"> + <td align="center" width="20%%" class="nav"> + <a class="nav" href="index.html"> + Home</a></td></a> + <a class="nav" href="installing.html"> + <td align="center" width="20%%" class="nav"> + <a class="nav" href="installing.html"> + Installing Epydoc</a></td></a> + <a class="nav" href="using.html"> + <td align="center" width="20%%" class="nav"> + <a class="nav" href="using.html"> + Using Epydoc</a></td></a> + <a class="nav" href="epytext.html"> + <td align="center" width="20%%" class="nav"> + <a class="nav" href="epytext.html"> + Epytext</a></td></a> + <td align="center" width="20%%" class="nav"> + + <A href="http://sourceforge.net/projects/epydoc"> + <IMG src="sflogo.png" + width="88" height="26" border="0" alt="SourceForge" + align="top"/></A></td> + </tr> +</table> +</body> +</html> +""" + +COLOR = {'def': '#705000', + 'defname': '#000080', + 'comment': '#005080', + 'command': '#705000', + 'escape': '#ffffff', + } +COLORIZE_RE = re.compile('|'.join(['(%s)' % s for s in [ + r'(?P<def>(re)?new(command|environment)){(?P<defname>[^}]+)}', + r'(?P<command>\\\w+)', + r'(?P<escape>\\.)', + r'(?P<comment>%.*)', + ]])) + +def subfunc(m): + if m.group('def') is not None: + return ('<code class="%s">%s</code>{<code class="%s">%s</code>}' % + ('keyword', m.group('def'), 'function', m.group('defname'))) + if m.group('command') is not None: + return '<code class="%s">%s</code>' % ('keyword', m.group('command')) + if m.group('escape') is not None: + return '<code class="%s">%s</code>' % ('escape', m.group('escape')) + if m.group('comment') is not None: + return '<code class="%s">%s</code>' % ('comment', m.group('comment')) + assert False, 'expected to match some group' + +def colorize(s, title): + s = s.replace('&', '&') + s = s.replace('<', '<') + s = s.replace('>', '>') + body = COLORIZE_RE.sub(subfunc, s) + return TEMPLATE % dict(title=title, body=body) + +def main(): + if len(sys.argv) != 2: + print 'Usage: %s <output-dir>' % sys.argv[0] + sys.exit(-1) + + # hackish to hardcode this; oh well. + sty_list = open('doc/epydoc-style-list.txt', 'w') + sty_list.write('.. This file is automatically generated by %s\n\n' % + sys.argv[0]) + + output_dir = sys.argv[1] + for (name, sheet) in sorted(STYLESHEETS.items()): + if name == 'default': pass + filename = 'epydoc-sty-%s.html' % name + title = 'LaTeX Style File: epydoc-%s.sty' % name + out = open(os.path.join(output_dir, filename), 'wb') + out.write(colorize(sheet, title)) + out.close() + sty_list.write('- `%s <%s>`__\n' % (title, filename)) + + sty_list.close() + + # hackish to hardcode this; oh well. + demo = open('doc/epydoc-latex-demo.tex').read() + out = open(os.path.join(output_dir, 'epydoc-latex-demo.html'), 'wb') + out.write(colorize(demo, 'Epydoc LaTeX Style Reference')) + out.close() + + +if __name__ == '__main__': + main() Property changes on: trunk/epydoc/src/tools/sty2html.py ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |