diff --git a/src/Export.py b/src/Export.py index d376cf0..7caddb8 100644 --- a/src/Export.py +++ b/src/Export.py @@ -1,12 +1,12 @@ -from NoteView import Title, Body, Image, List, Task +from NoteView import Title, Body, Image, List, Task, ElementError from gi.repository import Gtk -def export_to_markdown(content, path): +def export_to_markdown(content: list, path: str): # Purpose: Given list of elements, export them to a markdown file result = [] + broken = 0 for element in content: - # TODO: Export images if type(element.main) is Body: result.append(element.main.save()["text"]) elif type(element.main) is Title: @@ -15,10 +15,24 @@ def export_to_markdown(content, path): result += [f"- {item}" for item in element.main.save()["items"]] elif type(element.main) is Task: result += [f"- [{'x' if item[1] else ' '}] {item[0]}" for item in element.main.save()["items"]] - finalise(result, path) + elif type(element.main) is Image: + data = element.main.save() + try: + if data["source"] == "url": + result += [f"![{data['tooltip']}]({data['url']})"] + elif data["source"] == "file": + result += [f"![{data['tooltip']}]({data['file'][data['file'].find("/") + 1:]})"] + else: + broken += 1 + except KeyError: + broken += 1 + elif type(element.main) is ElementError: + broken += 1 + finalise(result, path, broken) -def finalise(data, path): + +def finalise(data: list, path: str, err: int): # Purpose: Given a list of the content of every element, # try and save the file to disk with each item being a new line try: @@ -26,7 +40,8 @@ def finalise(data, path): for line in data: file.write(line + "\n") dialogue = Gtk.MessageDialog(text="File Successfully Exported", - secondary_text=path[:path.rfind('.')] + ".md", + secondary_text=path[:path.rfind('.')] + ".md" + (f"\n{err} elements where skipped" + if err else ""), message_type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.OK) except: diff --git a/src/ImageInsert.py b/src/ImageInsert.py index b0fc170..7a62db8 100644 --- a/src/ImageInsert.py +++ b/src/ImageInsert.py @@ -85,7 +85,7 @@ def __init__(self, url_source, file_source, wikimedia_source, web_source, cache_ self.scale_slider.set_range(0, 1.5) self.scale_slider.set_digits(True) for i in range(0, 15): - self.scale_slider.add_mark(i/10, Gtk.PositionType.BOTTOM) + self.scale_slider.add_mark(i / 10, Gtk.PositionType.BOTTOM) # self.scale_slider.add_mark(1, Gtk.PositionType.BOTTOM) # # self.scale_slider = Gtk.Range() # self.scale_row.add_suffix(self.scale_slider) @@ -170,5 +170,5 @@ def get_values(self): "file": file, "scale": scale, "tooltip": tooltip} - # "cache": cache} + # "cache": cache} return data