summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2021-02-09 11:23:10 +0900
committerKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2021-02-09 11:23:47 +0900
commit483f8e658800cc62e854fc8a0c2abb4c3654376f (patch)
treebb7567297da0ba4095f5928e196a01ff609aac59 /scripts
parent0e370113e7af1aea544c832fa5fa23bf255eefcc (diff)
scripts: add html_wiki.py
Because current PeriJect is using scripts/myhtml.py to creating all HTML files, all files will be re-created if myhtml.py itself was updated. It is very verbose. This patch separates "wiki" from it. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/html_wiki.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/html_wiki.py b/scripts/html_wiki.py
new file mode 100755
index 0000000..1c84643
--- /dev/null
+++ b/scripts/html_wiki.py
@@ -0,0 +1,66 @@
+#! /usr/bin/env python3
+#===============================
+#
+# html_wiki
+#
+# 2021/02/09 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
+#===============================
+import textile
+import sys
+import re
+
+import html_base
+from html_base import html
+#====================================
+#
+# periject_html
+#
+#====================================
+class periject_html(html_base.myhtml):
+
+ def __init__(self):
+ super().__init__()
+
+ #--------------------
+ # print
+ #--------------------
+ def print(self, argv):
+ # remove this script
+ argv.pop(0)
+
+ with open(argv[0], "r") as f:
+ text = f.read()
+
+ # parse http[s]
+ text = re.sub(r'(\s+)http://(.*)(\s+)', r'\1"http://\2":http://\2\3', text)
+ text = re.sub(r'(\s+)https://(.*)(\s+)', r'\1"https://\2":https://\2\3', text)
+
+ # parse img
+ text = re.sub(r'!(\S+)!', r'!../../wiki/\1!', text)
+
+ # [[foo bar]]
+ # -> "foo bar":foo_bar.html
+ while 1:
+ hit = re.search(r'\[\[.*\]\]', text)
+
+ if (not hit):
+ break;
+
+ link = text[hit.start()+2:hit.end()-2]
+ link = "\"{}\":{}.html".format(link, re.sub(r' ', r'_', link))
+
+ text = text[:hit.start()] + link + text[hit.end():]
+
+ # textile
+ self.print_css("html/wiki")
+ with html("body"):
+ print(textile.textile(text))
+
+#====================================
+#
+# As command
+#
+#====================================
+if __name__=='__main__':
+ # html_wiki.py wiki/xxx.wiki
+ periject_html().print(sys.argv)