feat: Notify formatters if formatting first entry

This allows headers to be created by a formatter, which will
*only* be added to the very first entry created and not to
each entry. Currently for example this is used to create
a csv header but not for each document in turn.
This commit is contained in:
Marty Oehme 2024-06-12 11:45:35 +02:00
parent 9eb7399536
commit c2aec7add6
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
4 changed files with 39 additions and 7 deletions

View file

@ -28,7 +28,8 @@ class NotesExporter:
documents missing a note field or appends to existing.
"""
for doc, annots in annot_docs:
formatted_annotations = self.formatter(doc, annots).split("\n")
# first always true since we write single doc per note
formatted_annotations: list[str] = self.formatter(doc, annots, first=True).split("\n")
if formatted_annotations:
self._add_annots_to_note(doc, formatted_annotations, force=self.force)
@ -80,7 +81,9 @@ class NotesExporter:
# add newline if theres no empty space at file end
if len(existing) > 0 and existing[-1].strip() != "":
f.write("\n")
f.write("\n\n".join(new_annotations))
# FIXME this either joins them too close or moves them too far apart
# We need a better algorithm which knows what a full 'annotation' is.
f.write("\n".join(new_annotations))
f.write("\n")
logger.info(
f"Wrote {len(new_annotations)} "

View file

@ -20,7 +20,9 @@ class StdoutExporter:
the annotations in somewhat of a list form.
Not intended for machine-readability.
"""
first_entry = True
for doc, annots in annot_docs:
output: str = self.formatter(doc, annots)
output: str = self.formatter(doc, annots, first=first_entry)
if output:
print("{output}\n".format(output=output.rstrip("\n")))
first_entry = False