Skip to content

Commit aba615c

Browse files
Vitaliy RodnenkoVitaliy Rodnenko
authored andcommitted
Merge branch 'MattHulse-master'
2 parents 8245660 + 3844528 commit aba615c

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed

geeknote/editor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,15 @@ def ENMLtoText(contentENML):
9393

9494
Editor.checklistInENMLtoSoup(soup)
9595

96+
for section in soup.findAll('en-todo', checked='true'):
97+
section.replace_with('[x]')
98+
99+
for section in soup.findAll('en-todo'):
100+
section.replace_with('[ ]')
101+
96102
# content = html2text.html2text(soup.prettify())
97103
content = html2text.html2text(str(soup))
104+
98105
content = re.sub(r' *\n', os.linesep, content)
99106

100107
return content.encode('utf-8')
@@ -179,6 +186,10 @@ def textToENML(content, raise_ex=False, format='markdown'):
179186
contentHTML = u''.join(('<pre>', content, '</pre>')).encode("utf-8")
180187
else:
181188
contentHTML = Editor.HTMLEscape(content)
189+
190+
contentHTML = contentHTML.replace('[x]','<en-todo checked="true"></en-todo>')
191+
contentHTML = contentHTML.replace('[ ]','<en-todo></en-todo>')
192+
182193
return Editor.wrapENML(contentHTML)
183194
except:
184195
import traceback

geeknote/geeknote.py

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -804,51 +804,20 @@ def _createSearchRequest(self, search=None, tags=None,
804804
return request
805805

806806

807-
def modifyArgsByStdinStream():
808-
"""Parse the stdin stream for arguments"""
809-
content = sys.stdin.read()
810-
content = tools.stdinEncode(content)
811-
812-
if not content:
813-
out.failureMessage("Input stream is empty.")
814-
return tools.exitErr()
815-
816-
title = ' '.join(content.split(' ', 5)[:-1])
817-
title = re.sub(r'(\r\n|\r|\n)', r' ', title)
818-
if not title:
819-
out.failureMessage("Error while creating title of note from stream.")
820-
return tools.exitErr()
821-
elif len(title) > 50:
822-
title = title[0:50] + '...'
823-
824-
ARGS = {
825-
'title': title,
826-
'content': content
827-
}
828-
829-
return ('create', ARGS)
830-
831-
832807
def main(args=None):
833808
try:
834809
exit_status_code = 0
835810

836-
# if terminal
837-
if config.IS_IN_TERMINAL:
838-
sys_argv = sys.argv[1:]
839-
if isinstance(args, list):
840-
sys_argv = args
811+
sys_argv = sys.argv[1:]
812+
if isinstance(args, list):
813+
sys_argv = args
841814

842-
sys_argv = tools.decodeArgs(sys_argv)
815+
sys_argv = tools.decodeArgs(sys_argv)
843816

844-
COMMAND = sys_argv[0] if len(sys_argv) >= 1 else None
817+
COMMAND = sys_argv[0] if len(sys_argv) >= 1 else None
845818

846-
aparser = argparser(sys_argv)
847-
ARGS = aparser.parse()
848-
849-
# if input stream
850-
else:
851-
COMMAND, ARGS = modifyArgsByStdinStream()
819+
aparser = argparser(sys_argv)
820+
ARGS = aparser.parse()
852821

853822
# error or help
854823
if COMMAND is None or ARGS is False:

0 commit comments

Comments
 (0)