diff --git a/src/functions.py b/src/functions.py index 60f3c59..1e11ff7 100755 --- a/src/functions.py +++ b/src/functions.py @@ -50,7 +50,12 @@ def convert_text(text: str, format_indents: bool = True): for line in seperate(text): # add anki field into line and count the number of changes if as_indent and re.search(r"^\W+.+", line) is not None: - newLine, _ = re.subn(r"(^\W+)(.+)", r"\1 {{{{c1::\2}}}}", line) + if re.search(r"^\t+", line) is not None: + newLine = match_and_replace(line, format_indents) + else: + newLine, _ = re.subn( + r"(?!^\t|^.+:$)^(\W+)(.+)$", r"\1 {{c1::\2}}", line + ) else: as_indent = False newLine = match_and_replace(line, format_indents) @@ -66,10 +71,10 @@ def match_and_replace(line: str, format_indents: bool = True): if re.search(":$", line) is not None: return True if format_indents: - line, num = re.subn("(\t+.)(..*)", r"\1 {{{{c1::\2}}}}", line) + line, num = re.subn("(\t+.)(..*)", r"\1 {{c1::\2}}", line) if num > 0: return line - line, num = re.subn("(:)(..+)", r"\1 {{{{c1::\2}}}}", line) + line, num = re.subn("(:)(..+)", r"\1 {{c1::\2}}", line) return line