(Arne Babenhauserheide)
2014-02-09: Parse Markdown (if available), and leave 6 lines for the intro, Parse Markdown (if available), and leave 6 lines for the intro, because Markdown headlines eat one line.
diff --git a/staticsite.py b/staticsite.py
--- a/staticsite.py
+++ b/staticsite.py
@@ -24,6 +24,7 @@ import mercurial
import ftplib
import socket
import datetime
+import codecs
from mercurial import cmdutil, util, scmutil
from mercurial import commands, dispatch
from mercurial.i18n import _
@@ -523,8 +524,8 @@ div.screenshots img{
#shortlog a:hover, #branches a:hover, #tags a:hover, #bookmarks a:hover, #incoming a:hover, #outgoing a:hover, #log a{
text-decoration:underline;
}
-#intro pre{
- background:#eeeeee;border:solid thin lightgray;border-radius:25px;color:#353535;font:normal 23px/25px Palatino,"Palatino Linotype",serif;text-rendering:optimizeLegibility;font-style:italic;padding-left:25px;padding-right:25px;padding-bottom:25px;padding-top:20px;
+#intro>pre{
+ color:#353535;font:normal 23px/25px Palatino,"Palatino Linotype",serif;text-rendering:optimizeLegibility;font-style:italic;padding-left:25px;padding-right:25px;padding-bottom:25px;padding-top:20px;/*background:#eeeeee;border:solid thin lightgray;border-radius:25px;*/
}
#readme>pre{
background:#fdfdfd;color:#353535;font:normal 18px/25px Palatino,"Palatino Linotype",serif;text-rendering:optimizeLegibility;
@@ -701,10 +702,11 @@ def parsereadme(filepath, truncated=Fals
"""Parse the readme file"""
with open(filepath) as r:
readme = r.read()
+ # TODO: Markdown parsing belongs here.
if truncated:
- return "<pre style=\"white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;\">" + "\n".join(readme.splitlines()[:5]) + "</pre>"
+ return "<pre markdown=\"1\" style=\"white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;\">" + "\n".join(readme.splitlines()[:6]) + "</pre>"
else:
- return "<pre style=\"white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;\">" + readme + "</pre>"
+ return "<pre markdown=\"1\" style=\"white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;\">" + readme + "</pre>"
def overviewlogstring(ui, repo, revs, template=templates["commitlog"]):
"""Get the string for a log of the given revisions for the overview page."""
@@ -761,7 +763,13 @@ def writeoverview(ui, repo, target, name
readme = parsereadme(os.path.join(repo.root, f))
readme_intro = parsereadme(os.path.join(repo.root, f), truncated=True)
overview += "<div id='intro'>"
- overview += readme_intro
+ try: # to use markdown if we can
+ import markdown
+ overview += markdown.markdown(
+ unicode(readme_intro, encoding="utf-8"),
+ extensions=["markdown.extensions.extra"]).encode("utf-8")
+ except ImportError:
+ overview += readme_intro
overview += "</div>"
break
@@ -830,7 +838,13 @@ def writeoverview(ui, repo, target, name
# add the full readme
ui.debug("[staticsite] writeoverview: readme\n")
overview += "<div id='readme'><h2>"+_("Readme")+"</h2>\n"
- overview += readme
+ try: # to use markdown if we can
+ import markdown
+ overview += markdown.markdown(
+ unicode(readme, encoding="utf-8"),
+ extensions=["markdown.extensions.extra"]).encode("utf-8")
+ except ImportError:
+ overview += readme
overview += "</div>"
# finish the overview