Add support for calling an external program to generate README markup
Sun Nov 13 11:23:24 UTC 2011 pinterface <pix@kepibu.org>
* Add support for calling an external program to generate README markup
diff -rN -u old-darcsweb/config.py.sample new-darcsweb/config.py.sample
--- old-darcsweb/config.py.sample 2013-07-18 20:23:57.000000000 +0000
+++ new-darcsweb/config.py.sample 2013-07-18 20:23:57.000000000 +0000
@@ -84,6 +84,10 @@
# option.
#disable_annotate = True
+ # If you'd like a wider range of README file types than darcsweb
+ # provides, set readme_converter to a program which takes a single
+ # argument--the name of the readme file--and outputs HTML.
+ #readme_converter = 'ruby -rubygems /var/lib/gems/1.8/gems/github-markup-0.5.3/bin/github-markup'
#
diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi
--- old-darcsweb/darcsweb.cgi 2013-07-18 20:23:57.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2013-07-18 20:23:57.000000000 +0000
@@ -1091,6 +1091,29 @@
return parse_annotate(run_darcs(cmd))
+def get_readme():
+ import glob
+ readmes = glob.glob("README*")
+ if len(readmes) == 0: return False, False
+ import re
+ for p in readmes:
+ file = os.path.basename(p)
+ if re.search('\.(md|markdown)$', p):
+ import codecs
+ import markdown
+ f = codecs.open(p, encoding=config.repoencoding[0])
+ str = f.read()
+ html = markdown.markdown(str, ['extra', 'codehilite(css_class=page_body)'])
+ return file, fixu8(html)
+ elif re.search('README$', p):
+ f = open(p)
+ str = f.read()
+ return file, '<pre>%s</pre>' % fixu8(escape(str))
+ # We can't handle this ourselves, try shelling out
+ if not config.readme_converter: return False, False
+ cmd = '%s "%s"' % (config.readme_converter, readmes[0])
+ inf, outf = os.popen2(cmd, 't')
+ return os.path.basename(readmes[0]), fixu8(outf.read())
#
@@ -1222,30 +1245,11 @@
print "</table>"
-# FIXME: shell out to github-markup to avoid duplicating that effort here?
def print_readme():
- real = False
- for p in ["README", "README.md", "README.markdown"]:
- p = realpath(p)
- if p and os.path.isfile(p):
- real = p
- break
- if not real: return
-
- print '<div class="title">%s</div>' % os.path.basename(real)
-
- import re
- if re.search('\.(md|markdown)$', real):
- import codecs
- import markdown
- f = codecs.open(real, encoding=config.repoencoding[0])
- str = f.read()
- html = markdown.markdown(str, ['extra', 'codehilite(css_class=page_body)'])
- print '<section>%s</section>' % fixu8(html)
- else:
- f = open(real)
- str = f.read()
- print '<section><pre>%s</pre></section>' % fixu8(escape(str))
+ head, body = get_readme()
+ if not head: return False
+ print '<div class="title">%s</div>' % head
+ print '<section>%s</section' % body
def print_log(last = PATCHES_PER_PAGE, topi = 0):
@@ -2559,6 +2563,11 @@
else:
config.disable_annotate = False
+ if "readme_converter" in dir(base):
+ config.readme_converter = base.readme_converter
+ else:
+ config.readme_converter = False
+
#