fix: exported notes are html, so don't render them again, potentially breaking stuff.

This commit is contained in:
redxef 2025-03-12 00:24:24 +01:00
parent 2964baed39
commit 585eb3c70a
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
78 changed files with 12 additions and 7 deletions

View file

@ -36,7 +36,7 @@ def process_line(
slug = slug.replace(' ', '-')
base_filename = deckpath / slug
for i, c in enumerate(columns):
with (base_filename.parent / (base_filename.name + f'.{i}.md')).open('w') as fp:
with (base_filename.parent / (base_filename.name + f'.{i}.html')).open('w') as fp:
fp.write(c)
if not c.endswith('\n'):
fp.write('\n')

View file

@ -9,7 +9,7 @@ import random
import re
RE_DIRNAME = re.compile(r'^(.*)\.([0-9]+)\.([0-9]+)$')
RE_FILENAME = re.compile(r'^(.*)\.([0-9]+)\.md$')
RE_FILENAME = re.compile(r'^(.*)\.([0-9]+)\.(md|html)$')
class MyNote(genanki.Note):
pass
@ -20,20 +20,25 @@ def load_notes(
model: genanki.Model,
) -> list[genanki.Note]:
files_loaded = []
final_files: dict[str, list[tuple[pathlib.Path, int]]] = {}
final_files: dict[str, list[tuple[pathlib.Path, int, bool]]] = {}
for dirpath, _, filenames in path.walk():
files_loaded += [dirpath / x for x in filenames]
for f in files_loaded:
match = RE_FILENAME.match(f.name)
if match:
final_files.setdefault(match.group(1), []).append((f, int(match.group(2))))
final_files.setdefault(match.group(1), []).append(
(f, int(match.group(2)), match.group(3) == 'html'),
)
notes: list[genanki.Note] = []
for v in final_files.values():
note_files: list[pathlib.Path] = [v_[0] for v_ in sorted(v, key=lambda x: x[1])]
note_files: list[tuple[pathlib.Path, bool]] = [(v_[0], v_[2]) for v_ in sorted(v, key=lambda x: x[1])]
note_str: list[str] = []
for f in note_files:
for f, is_html in note_files:
with f.open() as fp:
html_str = markdown.markdown(fp.read())
if is_html:
html_str = fp.read()
else:
html_str = markdown.markdown(fp.read())
note_str += [html_str]
notes += [MyNote(model=model, fields=note_str, guid=genanki.guid_for(note_str[0]))]
return notes