Add support for calling an external program to generate README markup --> to head
/config.py.sample
Ignoring non-repository paths: /config.py.sample
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-06-14 23:58:24.000000000 +0000
+++ new-darcsweb/config.py.sample 2013-06-14 23:58:24.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-06-14 23:58:24.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2013-06-14 23:58:24.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):
@@ -1371,6 +1375,35 @@
cssclass='page_body')
print pygments.highlight(code, lexer, formatter)
+ print """<script type='text/javascript'>
+(function () {
+ if (!document.getElementsByClassName || !document.evaluate || !window.addEventListener)
+ return;
+
+ function fakeAnchors () {
+ var pbody = document.getElementsByClassName("page_body")[0];
+ var anchor = window.location.hash;
+ if (!pbody || "" == anchor || "#" == anchor) return;
+
+ /* Avoid xpath injection, because so far as I can tell there's no way to set
+ xpath variables from JavaScript. */
+ if (anchor.match(/['"]/)) return;
+
+ anchor = anchor.substr(1);
+ var parts = anchor.split(/ /);
+ var xpq = '//span[string()="'+parts[0]+'"]';
+ for (var i = 1; i < parts.length; i++) {
+ xpq += '//following-sibling::span[1][string()="'+parts[i]+'"]';
+ }
+ var res = document.evaluate(xpq, pbody, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
+ if (!res || !res.singleNodeValue) return;
+
+ res.singleNodeValue.scrollIntoView(true);
+ };
+ window.addEventListener("DOMContentLoaded", fakeAnchors, false);
+ window.addEventListener("hashchange", fakeAnchors, false);
+})();
+</script>"""
def print_annotate(ann, style):
print '<div class="page_body">'
@@ -2285,7 +2318,9 @@
# some python magic
alt = True
- for conf in dir(all_configs):
+ confs = dir(all_configs)
+ confs.sort(key=str.lower)
+ for conf in confs:
if conf.startswith('__'):
continue
c = all_configs.__getattribute__(conf)
@@ -2559,6 +2594,11 @@
else:
config.disable_annotate = False
+ if "readme_converter" in dir(base):
+ config.readme_converter = base.readme_converter
+ else:
+ config.readme_converter = False
+
#
diff -rN -u old-darcsweb/style.css new-darcsweb/style.css
--- old-darcsweb/style.css 2013-06-14 23:58:24.000000000 +0000
+++ new-darcsweb/style.css 2013-06-14 23:58:24.000000000 +0000
@@ -9,11 +9,12 @@
body {
font-family: sans-serif;
- font-size: 12px;
+ font-size: 1em;
margin:0px;
border:solid #d9d8d1;
border-width:1px;
- margin:10px;
+ margin:0.8em;
+ margin-bottom: 60%;
}
a {
@@ -25,37 +26,29 @@
}
div.page_header {
- height:25px;
- padding:8px;
- font-size:18px;
+ padding:0.5em;
+ font-size:1.5em;
font-weight:bold;
background-color:#d9d8d1;
}
-div.page_header a:visited {
- color:#0000cc;
-}
-
div.page_header a:hover {
color:#880000;
}
div.page_nav {
- padding:8px;
-}
-div.page_nav a:visited {
- color:#0000cc;
+ padding:0.5em;
}
div.page_path {
- padding:8px;
+ padding:0.5em;
border:solid #d9d8d1;
border-width:0px 0px 1px
}
div.page_footer {
- height:17px;
- padding:4px 8px;
+ overflow:auto;
+ padding:0.25em 0.5em;
background-color: #d9d8d1;
}
@@ -66,7 +59,7 @@
}
div.page_body {
- padding:8px;
+ padding:0.5em;
}
div.search_box {
@@ -75,18 +68,16 @@
}
input.search_text {
- font-size:xx-small;
+ font-size:0.66em;
background-color: #edece6;
- vertical-align: top;
}
input.search_button {
- font-size:xx-small;
- vertical-align: top;
+ font-size:0.66em;
}
div.title, a.title {
- display:block; padding:6px 8px;
+ display:block; padding:0.5em;
font-weight:bold;
background-color:#edece6;
text-decoration:none;
@@ -98,34 +89,35 @@
}
div.title_text {
- padding:6px 0px;
+ padding: 0.5em 0;
border: solid #d9d8d1;
border-width:0px 0px 1px;
}
div.log_body {
- padding:8px 8px 8px 150px;
+ padding:0.5em;
+ padding-left:10.5em;
}
span.age {
position:relative;
float:left;
- width:142px;
+ width:10em;
font-style:italic;
}
div.log_link {
- padding:0px 8px;
- font-size:10px;
+ padding:0 0 0 0.625em;
+ font-size:0.8em;
font-family:sans-serif;
font-style:normal;
position:relative;
float:left;
- width:136px;
+ width:12.5em;
}
div.list_head {
- padding:6px 8px 4px;
+ padding:0.5em;
border:solid #d9d8d1;
border-width:1px 0px 0px;
font-style:italic;
@@ -153,12 +145,11 @@
table {
/*clear:both;*/
- padding:8px 4px;
+ padding:0.5em 0.25em;
}
th {
- padding:2px 5px;
- font-size:12px;
+ padding:0.25em 0.5em;
text-align:left;
}
@@ -183,20 +174,15 @@
}
td {
- padding:2px 5px;
- font-size:12px;
- vertical-align:top;
+ padding:0.25em 0.5em;
}
td.link {
- padding:2px 5px;
- font-family:sans-serif;
- font-size:10px;
+ font-size:0.8em;
}
div.pre {
font-family:monospace;
- font-size:12px;
white-space:pre;
}
@@ -228,7 +214,6 @@
a.annotate_desc {
color:#999999;
text-decoration:none;
- font-size:11px;
}
a.annotate_desc:hover {
@@ -237,16 +222,13 @@
a.rss_logo {
float:right;
- padding:3px 0px;
- width:35px;
- line-height:10px;
- border:1px solid;
- border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
+ padding:0.25em 0.5em;
+ border:1px outset;
color:#ffffff;
background-color:#ff6600;
font-weight:bold;
font-family:sans-serif;
- font-size:10px;
+ font-size:0.8em;
text-align:center;
text-decoration:none;
}
@@ -256,10 +238,10 @@
}
img.logo {
- border-width:0px;
+ border-width:0;
vertical-align:top;
- margin-left:12pt;
- margin-right:5pt;
+ margin-left:1em;
+ margin-right:0.25em;
}