Skip to content

Commit

Permalink
Added a simple unstyled template to the build_docs script. The genera…
Browse files Browse the repository at this point in the history
…ted docs (should) now validate as xhtml - assuming they parse correctly. I suspect the docs need some updating though.
  • Loading branch information
Waylan Limberg committed Aug 20, 2010
1 parent dc63c68 commit bba9fc5
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# The command line script name. Currently set to "markdown_py" so as not to
# conflict with the perl implimentation (which uses "markdown"). We can't use
# "markdown.py" as the default config on some systems will cause the script to
# try to import itself rather than the library which raised an error.
# try to import itself rather than the library which will raise an error.
SCRIPT_NAME = 'markdown_py'

class md_install_scripts(install_scripts):
Expand All @@ -42,8 +42,22 @@ def run(self):
print ('ERROR: Unable to create %s: %s' % (bat_path, err))


doc_header = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>%(title)s</title>
</head>
<body>
"""

doc_footer = """
</body>
</html>
"""

class build_docs(Command):
""" Build mardkown documentation into html."""
""" Build markdown documentation into html."""

description = '"build" documentation (convert markdown text to html)'

Expand All @@ -70,6 +84,19 @@ def _get_docs(self):
for file in files:
yield os.path.join(root, file)

def _get_page_title(self, path):
""" Get page title from file name (and path). """
root, ext = os.path.splitext(path)
path, name = os.path.split(root)
parts = path.split(os.sep)
parts = [x.replace('_', ' ').capitalize() for x in parts[1:]]
if name.lower() != 'index':
parts.append(name.replace('_', ' ').capitalize())
if parts:
return ' | '.join(parts) + ' &#8212; Python Markdown'
else:
return 'Python Markdown'

def run(self):
try:
import markdown
Expand All @@ -80,15 +107,20 @@ def run(self):
for doc in self.docs:
outfile, ext = os.path.splitext(doc)
if ext == '.txt':
title = self._get_page_title(outfile)
outfile += '.html'
outfile = change_root(self.build_base, outfile)
self.mkpath(os.path.split(outfile)[0])
if self.force or newer(doc, outfile):
if self.verbose:
print ('Converting %s ---> %s' % (doc, outfile))
if not self.dry_run:
outfile = open(outfile, 'w')
outfile.write(doc_header % {'title': title})
md.convertFile(doc, outfile)
md.reset()
outfile.write(doc_footer)
outfile.close()
else:
if self.verbose:
print ('Skipping... (%s is newer)' % outfile)
Expand Down Expand Up @@ -135,3 +167,4 @@ def run(self):
data['install_requires'] = ['elementtree']

setup(**data)

0 comments on commit bba9fc5

Please sign in to comment.