Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit 21cbc2b

Browse files
committed
Merge branch 'lczaplinski/bugfix/todos' of https://github.com/scoiatael/geeknote into 2.0.17
2 parents 431a389 + fe3b887 commit 21cbc2b

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

geeknote/editor.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,11 @@ def checklistInENMLtoSoup(soup):
7171
'''
7272
Transforms Evernote checklist elements to github `* [ ]` task list style
7373
'''
74-
transform_tags = ['p', 'div']
74+
for section in soup.findAll('en-todo', checked='true'):
75+
section.replace_with('<br />* [x]')
7576

76-
# soup.select cant be used with dashes: https://bugs.launchpad.net/beautifulsoup/+bug/1276211
77-
for todo in soup.find_all('en-todo'):
78-
parent = todo.parent
79-
transform = parent.find() == todo and parent.name in transform_tags
80-
81-
checked = todo.attrs.get('checked', None) == "true"
82-
todo.replace_with("[x] " if checked else "[ ] ")
83-
84-
# EN checklist can appear anywhere, but if they appear at the beginning
85-
# of a block element, transform it so it ressembles github markdown syntax
86-
if transform:
87-
content = ''.join(unicode(child) for child in parent.children
88-
if isinstance(child, NavigableString)
89-
).strip()
90-
91-
new_tag = soup.new_tag("li")
92-
new_tag.string = content
93-
parent.replace_with(new_tag)
77+
for section in soup.findAll('en-todo'):
78+
section.replace_with('<br />* [ ]')
9479

9580
@staticmethod
9681
def ENMLtoText(contentENML, format='default', imageOptions={'saveImages': False}, imageFilename=""):
@@ -133,12 +118,6 @@ def ENMLtoText(contentENML, format='default', imageOptions={'saveImages': False}
133118

134119
Editor.checklistInENMLtoSoup(soup)
135120

136-
for section in soup.findAll('en-todo', checked='true'):
137-
section.replace_with('[x]')
138-
139-
for section in soup.findAll('en-todo'):
140-
section.replace_with('[ ]')
141-
142121
# change <en-media> tags to <img> tags
143122
if 'saveImages' in imageOptions and imageOptions['saveImages']:
144123
for section in soup.findAll('en-media'):

tests/test_editor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ def test_ENMLToText(self):
3434
self.assertEqual(Editor.ENMLtoText(wrapped), self.MD_TEXT)
3535

3636
def test_TODO(self):
37-
self.assertEqual(Editor.textToENML("- [ ] item 1\n- [x] item 2\n- [ ] item 3"),
38-
Editor.wrapENML("<div><en-todo></en-todo>item 1</div><div><en-todo checked=\"true\"></en-todo>item 2</div><div><en-todo></en-todo>item 3</div>\n"))
37+
MD_TODO = "\n* [ ]item 1\n\n* [x]item 2\n\n* [ ]item 3\n\n"
38+
HTML_TODO = "<div><en-todo></en-todo>item 1</div><div><en-todo checked=\"true\"></en-todo>item 2</div><div><en-todo></en-todo>item 3</div>\n"
39+
self.assertEqual(Editor.textToENML(MD_TODO),
40+
Editor.wrapENML(HTML_TODO))
41+
42+
wrapped = Editor.wrapENML(HTML_TODO)
43+
text = Editor.ENMLtoText(wrapped)
44+
self.assertEqual(text, MD_TODO)
3945

4046
def test_htmlEscape(self):
4147
wrapped = Editor.textToENML(content="<what ever>", format="markdown")

0 commit comments

Comments
 (0)