ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From humbed...@apache.org
Subject [1/2] incubator-ponymail-site git commit: turn h1-h6 into links, using the title as ID
Date Wed, 01 Jun 2016 04:17:00 GMT
Repository: incubator-ponymail-site
Updated Branches:
  refs/heads/asf-site f1083e144 -> 44f3401f0


turn h1-h6 into links, using the title as ID


Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail-site/commit/93465c22
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail-site/tree/93465c22
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail-site/diff/93465c22

Branch: refs/heads/asf-site
Commit: 93465c223e279718638d8a3a91e5e11f7b196c0f
Parents: f1083e1
Author: humbedooh <humbedooh@apache.org>
Authored: Wed Jun 1 06:14:43 2016 +0200
Committer: humbedooh <humbedooh@apache.org>
Committed: Wed Jun 1 06:14:43 2016 +0200

----------------------------------------------------------------------
 source/generate.py | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail-site/blob/93465c22/source/generate.py
----------------------------------------------------------------------
diff --git a/source/generate.py b/source/generate.py
index 9c76c4f..4de9c47 100644
--- a/source/generate.py
+++ b/source/generate.py
@@ -22,6 +22,14 @@ def runDir(path):
             text = re.sub(r"~~~([\s\S]+?)~~~", "<pre>\\1</pre>", text, flags=re.MULTILINE)
             text = re.sub(r"([A-Z/]+)\.md", lambda x: x.group(1).lower() + ".html", text,
flags =re.MULTILINE)
             html = markdown.markdown(text)
+            # Convert h1-h6 into links
+            html = re.sub(r"<h([1-6])>(.+?)</h[1-6]>", lambda x: "<h%s id='%s'>%s</h%s>"
% (
+                x.group(1),
+                re.sub(r"[^a-z0-9]+", "", x.group(2).lower()),
+                x.group(2),
+                x.group(1)
+                       )
+                          , html)
             html = template.replace("%CONTENT%", html, 1)
             print("Writing %s..." % outfile)
             bpath = os.path.dirname(outfile)


Mime
View raw message