From 0a065164e9a625d8d6cb1c2c0f5e40cd27a2c6cc Mon Sep 17 00:00:00 2001 From: Alan Crouau Date: Fri, 7 Aug 2015 00:16:17 +0200 Subject: [PATCH] gnsync create/update file in plain or markdown format --- geeknote/editor.py | 8 +++++--- geeknote/gnsync.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/geeknote/editor.py b/geeknote/editor.py index d7e2853..fc5b1fc 100644 --- a/geeknote/editor.py +++ b/geeknote/editor.py @@ -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'): @@ -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') diff --git a/geeknote/gnsync.py b/geeknote/gnsync.py index 9b5342d..f54a877 100644 --- a/geeknote/gnsync.py +++ b/geeknote/gnsync.py @@ -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 @@ -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 @@ -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))