#! /usr/bin/env python3 #=============================== # # html_wiki # # 2021/02/09 Kuninori Morimoto #=============================== 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)