Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions geeknote/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def checklistInENMLtoSoup(soup):


@staticmethod
def ENMLtoText(contentENML):
def ENMLtoText(contentENML, markdown=True):
soup = BeautifulSoup(contentENML.decode('utf-8'))

for section in soup.select('li > p'):
Expand All @@ -97,8 +97,10 @@ def ENMLtoText(contentENML):

for section in soup.findAll('en-todo'):
section.replace_with('[ ]')

content = html2text.html2text(str(soup).decode('utf-8'), '', 0)
if markdown:
content = html2text.html2text(str(soup).decode('utf-8'), '', 0)
else:
content = soup.get_text()
content = re.sub(r' *\n', os.linesep, content)

return content.encode('utf-8')
Expand Down
6 changes: 3 additions & 3 deletions geeknote/gnsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _update_file(self, file_note, note):
Updates file from note
"""
GeekNote().loadNoteContent(note)
content = Editor.ENMLtoText(note.content)
content = Editor.ENMLtoText(note.content, self.format == "markdown")
open(file_note['path'], "w").write(content)

@log
Expand Down Expand Up @@ -225,7 +225,7 @@ def _create_file(self, note):
Creates file from note
"""
GeekNote().loadNoteContent(note)
content = Editor.ENMLtoText(note.content)
content = Editor.ENMLtoText(note.content, self.format == "markdown")
path = os.path.join(self.path, note.title + self.extension)
open(path, "w").write(content)
return True
Expand All @@ -240,7 +240,7 @@ def _get_file_content(self, path):
# strip unprintable characters
content = remove_control_characters(content.decode('utf-8')).encode('utf-8')
content = Editor.textToENML(content=content, raise_ex=True, format=self.format)

if content is None:
logger.warning("File {0}. Content must be " \
"an UTF-8 encode.".format(path))
Expand Down