Skip to content

Commit

Permalink
- Removed words.txt
Browse files Browse the repository at this point in the history
- Added image support to markdown export
Now all commits are signed using RSA
  • Loading branch information
Wemmy0 committed Feb 12, 2024
1 parent ed0b935 commit b29ba19
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 21 additions & 6 deletions src/Export.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -15,18 +15,33 @@ 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:
with open(path[:path.rfind('.')] + ".md", "w+") as file:
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:
Expand Down
4 changes: 2 additions & 2 deletions src/ImageInsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -170,5 +170,5 @@ def get_values(self):
"file": file,
"scale": scale,
"tooltip": tooltip}
# "cache": cache}
# "cache": cache}
return data

0 comments on commit b29ba19

Please sign in to comment.