Added HTML formatter for gadialog files.
--- a/Makefile Fri Aug 21 12:17:35 2020 +0300
+++ b/Makefile Fri Aug 21 12:18:08 2020 +0300
@@ -156,7 +156,9 @@
$(patsubst %.gaphrase,dist/anki/%.apkg,$(GAPHRASE_FILES)) \
$(patsubst %.gadialog,dist/anki/%.apkg,$(GADIALOG_FILES))
-DICT_HTML_FILES := $(patsubst %.gadict,dist/html/%.html,$(GADICT_FILES))
+DICT_HTML_FILES := \
+ $(patsubst %.gadict,dist/html/%.html,$(GADICT_FILES)) \
+ dist/html/gadialog.html
RST_TMPL_FILE = dist/misc/rst.tmpl
RST_CSS_FILE = www/tmpl/rst.css
@@ -716,6 +718,9 @@
dist/html/%.html: %.gadict py/gadict.py py/gadict_html.py $(FREQLIST_DEP) $(MAKEFILE_LIST) | dist/html/
python3 -B py/gadict_html.py $(FREQLIST_OPT) $< $@
+dist/html/gadialog.html: gadialog.gadialog py/gadialog.py py/gadialog_html.py | dist/html/
+ python3 -B py/gadialog_html.py $< $@
+
dist/html/:
mkdir -p $@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/py/gadialog_html.py Fri Aug 21 12:18:08 2020 +0300
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+"""HTML format writer"""
+
+import io
+import sys
+import codecs
+import html
+
+import gadialog
+
+FINAME = None
+FONAME = None
+
+for idx in range(1, len(sys.argv)):
+ arg = sys.argv[idx]
+ if not FINAME:
+ FINAME = arg
+ continue
+ if not FONAME:
+ FONAME = arg
+ continue
+ raise Exception("Superfluous argument: '{:s}'".format(arg))
+
+if not FINAME:
+ raise Exception("Input file name is not passed...")
+if FONAME is None:
+ raise Exception("Output file name is not passed...")
+
+################################################################
+
+FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8")
+
+PARSER = gadialog.Parser()
+try:
+ DOM = PARSER.parse(FIN)
+finally:
+ FIN.close()
+
+if FONAME is None:
+ FOUT = sys.stdout
+else:
+ FOUT = codecs.open(FONAME, "w", "utf-8")
+
+################################################################
+
+HTML_HEADER = """<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>{title}</title>
+<style>
+body {{ max-width: 30em; margin: 0 auto; }}
+ul {{ list-style: none; }}
+li:before {{ content: "- " }}
+li.even:before {{ content: "ยป " }}
+.odd {{ color: blue; }}
+.even {{ color: green; }}
+</style>
+</head>
+<body>
+"""
+
+HTML_FOOTER = """</body>
+</html>
+"""
+
+NAME = html.escape("Dialogs")
+
+FOUT.write(HTML_HEADER.format(title=NAME))
+FOUT.write("<h1>{} dictionary</h1>\n".format(NAME))
+
+for num, lines in DOM.items():
+ FOUT.write("<hr>")
+ FOUT.write("<ul>\n")
+ odd = True
+ for line in lines:
+ FOUT.write('<li class="{:s}">{:s}</li>\n'.format("odd" if odd else "even", html.escape(line)))
+ odd = not odd
+ FOUT.write("</ul>")
+
+FOUT.write(HTML_FOOTER)
+FOUT.close()
+