summaryrefslogtreecommitdiff
path: root/scripts/html_wiki.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/html_wiki.py')
-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)