--- a/py/gaphrase_srs_anki.py Fri May 08 22:13:02 2020 +0300
+++ b/py/gaphrase_srs_anki.py Fri May 08 23:19:32 2020 +0300
@@ -65,7 +65,6 @@
COMMENT_RE = re.compile("^; ")
NUM_RE = re.compile(u"^# ([1-9][0-9]*)$")
- PHRASE_START_RE = re.compile(u"^- (.*)")
def __init__(self):
pass
@@ -86,7 +85,7 @@
def parse(self, stream):
self.lineno = 0
self.stream = stream
- self.dom = dict()
+ self.dom = dict() # num => phrase
self.eof = False
try:
self.parse_prelude()
@@ -113,31 +112,20 @@
"""Assume we are at ``# NUM`` line."""
num = self.num
phrase_buf = []
- phrases = []
while True:
self.readline()
if self.eof:
- if len(phrase_buf) > 0:
- phrases.append(" ".join(phrase_buf))
break
m = self.NUM_RE.match(self.line)
if m:
- if len(phrase_buf) > 0:
- phrases.append(" ".join(phrase_buf))
self.num = m.group(1)
break
- m = self.PHRASE_START_RE.match(self.line)
- if m:
- if len(phrase_buf) > 0:
- phrases.append(" ".join(phrase_buf))
- phrase_buf = [m.group(1)]
- else:
- phrase_buf.append(self.line)
- if len(phrases) == 0:
+ phrase_buf.append(self.line)
+ if len(phrase_buf) == 0:
raise ParseException("""There are no any phrases...""")
if num in self.dom:
raise ParseException("""Conflicting key: {}...""".format(num))
- self.dom[num] = phrases
+ self.dom[num] = " ".join(phrase_buf)
FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8")
@@ -160,12 +148,6 @@
.line {
margin-bottom: 0.5em;
}
-.odd {
- color: #004000;
-}
-.even {
- color: #000080;
-}
"""
class AnkiDbBuilder:
@@ -216,18 +198,6 @@
def close(self):
self.collection.close()
-def write_lines(buf, lines):
- odd = True
- for line in lines:
- if odd:
- buf.append("<div class='line odd'>")
- else:
- buf.append("<div class='line even'>")
- buf.append("- ")
- buf.append(line)
- buf.append("</div>")
- odd = not odd
-
# Looks like anki libs change working directory to media directory of current deck
# Therefore absolute path should be stored before creating temporary deck
FONAME = os.path.abspath(FONAME)
@@ -236,9 +206,11 @@
try:
BUILDER = AnkiDbBuilder(TMPDIR, NAME)
- for num, lines in DOM.items():
+ for num, phrase in DOM.items():
buf = []
- write_lines(buf, lines)
+ buf.append("<div class='line'>")
+ buf.append(phrase)
+ buf.append("</div>")
front = "".join(buf)
BUILDER.add_note(num, front)
BUILDER.export(FONAME)