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

Commit fc5d523

Browse files
author
dom
committed
merge
2 parents 097687e + 275b30a commit fc5d523

File tree

6 files changed

+71
-59
lines changed

6 files changed

+71
-59
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ For more information, see:
121121
$ geeknote settings
122122
Geeknote
123123
******************************
124-
Version: 2.0.12
124+
Version: 2.0.13
125125
App dir: /Users/username/.geeknote
126126
Error log: /Users/username/.geeknote/error.log
127127
Current editor: vim
@@ -165,6 +165,29 @@ $ geeknote settings --editor
165165
Current editor is: vim
166166
```
167167

168+
##### Enabling Markdown2 Extras
169+
170+
You can enable [Markdown2 Extras](https://github.com/trentm/python-markdown2/wiki/Extras) you want to use while editing notes. To check which settings are currently enabled call:
171+
172+
``` sh
173+
geeknote settings --extras
174+
```
175+
To change the Markdown2 Extras call:
176+
177+
```sh
178+
geeknote settings --extras "tables, footnotes"
179+
```
180+
###### Example
181+
182+
``` sh
183+
$ geeknote settings --extras
184+
current markdown2 extras is : ['None']
185+
$ geeknote settings --extras "tables, footnotes"
186+
Changes saved.
187+
$ geeknote settings --extras
188+
current markdown2 extras is : ['tables', 'footnotes']
189+
```
190+
168191
## Working with Notes
169192
### Notes: Creating notes
170193
The main functionality that we need is creating notes in Evernote.
@@ -195,6 +218,7 @@ geeknote create --title <title>
195218
| ‑‑reminder | date | Set reminder date and time in either 'yyyy-mm-dd' or 'yyyy-mm-dd HH:MM' format. Alternatively use TOMORROW and WEEK for 24 hours and a week ahead respectively, NONE for a reminder without a time. Use DONE to mark a reminder as completed. |
196219
| --urls | url | Set the URL for the note. |
197220
| --raw | | A flag signifying the content is in raw ENML format. |
221+
| --rawmd | | A flag signifying the content is in raw markdown format. |
198222

199223
##### Description
200224
This command allows us to create a new note in Evernote. Geeknote has designed for using in console, so we have some restrictions like inability to use double quotes in **--content** option. But there is a method to avoid it - use stdin stream or file synchronization, we show it later in documentation.
@@ -335,6 +359,7 @@ geeknote edit --note <title or GUID of note to edit>
335359
| ‑‑reminder | date | Set reminder date and time in either 'yyyy-mm-dd' or 'yyyy-mm-dd HH:MM' format. Alternatively use TOMORROW and WEEK for 24 hours and a week ahead respectively, NONE for a reminder without a time. Use DONE to mark a reminder as completed. Use DELETE to remove reminder from a note. |
336360
| --urls | url | Set the URL for the note. |
337361
| --raw | | A flag signifying the content is in raw ENML format. |
362+
| --rawmd | | A flag signifying the content is in raw markdown format. |
338363

339364
##### Examples
340365

geeknote.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Geeknote < Formula
55
homepage 'https://github.com/jeffkowalski/geeknote'
66
head 'https://github.com/jeffkowalski/geeknote.git'
77

8-
depends_on :python
8+
depends_on "python"
99

1010
resource "websocket-client" do
1111
url "https://files.pythonhosted.org/packages/a7/2b/0039154583cb0489c8e18313aa91ccd140ada103289c5c5d31d80fd6d186/websocket_client-0.40.0.tar.gz"

geeknote/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.12'
1+
__version__ = '2.0.13'

geeknote/editor.py

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919

2020
class EditorThread(threading.Thread):
21-
2221
def __init__(self, editor):
2322
threading.Thread.__init__(self)
2423
self.editor = editor
@@ -55,7 +54,8 @@ def HTMLUnescape(text):
5554
@staticmethod
5655
def getImages(contentENML):
5756
'''
58-
creates a list of image resources to save. each has a hash and extension attribute
57+
Creates a list of image resources to save.
58+
Each has a hash and extension attribute.
5959
'''
6060
soup = BeautifulSoup(contentENML.decode('utf-8'))
6161
imageList = []
@@ -81,7 +81,7 @@ def checklistInENMLtoSoup(soup):
8181
checked = todo.attrs.get('checked', None) == "true"
8282
todo.replace_with("[x] " if checked else "[ ] ")
8383

84-
# EN checklist can appear anywhere, but if they appear at the beggining
84+
# EN checklist can appear anywhere, but if they appear at the beginning
8585
# of a block element, transform it so it ressembles github markdown syntax
8686
if transform:
8787
content = ''.join(unicode(child) for child in parent.children
@@ -154,13 +154,10 @@ def ENMLtoText(contentENML, format='default', imageOptions={'saveImages': False}
154154
for section in soup.find_all('en-media'):
155155
section.replace_with(str(section))
156156

157-
# content = html2text.html2text(soup.prettify())
158-
# content = html2text.html2text(str(soup))
159-
# content = html2text.html2text(unicode(soup))
160157
content = html2text.html2text(str(soup).decode('utf-8'), '')
161158

162159
content = re.sub(r' *\n', os.linesep, content)
163-
content = content.replace(unichr(160), " ")
160+
content = content.replace(unichr(160), " ") # no-break space
164161
content = Editor.HTMLUnescape(content)
165162

166163
return content.encode('utf-8')
@@ -175,14 +172,13 @@ def wrapENML(contentHTML):
175172
@staticmethod
176173
def checklistInSoupToENML(soup):
177174
'''
178-
Transforms github style checklists `* [ ]` in the BeautifulSoup tree to
179-
enml.
175+
Transforms github style checklists `* [ ]` in the BeautifulSoup tree to ENML.
180176
'''
181177

182178
checktodo_re = re.compile(r'\[([ x])\]')
183179

184-
# To be more github compatible, if in a list all elements begins with `[ ]``
185-
# transform it to normal `[ ]` evernote elements
180+
# To be more github compatible, if all elements in a list begin with '[ ]',
181+
# convert them to en-todo evernote elements
186182
for ul in soup.find_all('ul'):
187183
tasks = []
188184
istodo = True
@@ -194,7 +190,6 @@ def checklistInSoupToENML(soup):
194190
reg = checktodo_re.match(li.get_text())
195191
istodo = istodo and reg
196192
character = reg.group(1) if reg else None
197-
198193
if character == "x":
199194
todo_tag['checked'] = "true"
200195

@@ -204,38 +199,32 @@ def checklistInSoupToENML(soup):
204199
tasks.append(task)
205200

206201
if istodo:
207-
for task in tasks:
202+
for task in tasks[::-1]:
208203
ul.insert_after(task)
209204
ul.extract()
210205

211-
# # For the rest of elements just replace `[ ]` with the appropriate element
212-
# for todo in soup.find_all(text=checktodo_re):
213-
# str_re = re.match(r'(.*)\[(.)\](.*)',todo)
214-
# pre = str_re.group(1)
215-
# post = str_re.group(3)
216-
#
217-
# todo_tag = soup.new_tag('en-todo')
218-
# if str_re.group(2) == "x": todo_tag['checked']="true"
219-
#
220-
# todo.replace_with(todo_tag)
221-
# todo_tag.insert_before(pre)
222-
# todo_tag.insert_after(post)
223-
224206
@staticmethod
225207
def textToENML(content, raise_ex=False, format='markdown', rawmd=False):
226208
"""
227-
Create an ENML format of note.
209+
Transform formatted text to ENML
228210
"""
229211

230212
if not isinstance(content, str):
231213
content = ""
232214
try:
233215
content = unicode(content, "utf-8")
234-
# add 2 space before new line in paragraph for creating br tags
235-
content = re.sub(r'([^\r\n])([\r\n])([^\r\n])', r'\1 \n\3', content)
236-
# content = re.sub(r'\r\n', '\n', content)
216+
content = re.sub(r'\r\n', '\n', content)
217+
218+
if format == 'pre':
219+
# For the 'pre' format, simply wrap the content with a 'pre' tag.
220+
# Do not perform any further parsing/mutation.
221+
contentHTML = u''.join(('<pre>', content, '</pre>')).encode("utf-8")
222+
elif format == 'markdown':
223+
# Markdown format https://daringfireball.net/projects/markdown/basics
224+
storage = Storage()
225+
extras = storage.getUserprop('markdown2_extras')
237226

238-
if format == 'markdown':
227+
if not rawmd:
239228
storage = Storage()
240229
extras = storage.getUserprop('markdown2_extras')
241230

@@ -246,26 +235,17 @@ def textToENML(content, raise_ex=False, format='markdown', rawmd=False):
246235

247236
soup = BeautifulSoup(contentHTML, 'html.parser')
248237
Editor.checklistInSoupToENML(soup)
249-
250-
# Non-Pretty HTML output
251238
contentHTML = str(soup)
252-
elif format == 'pre':
253-
#
254-
# For the 'pre' format, simply wrap the content with a 'pre' tag. Do
255-
# perform any parsing/mutation.
256-
#
257-
contentHTML = u''.join(('<pre>', content, '</pre>')).encode("utf-8")
258239
elif format == 'html':
259240
# Html to ENML http://dev.evernote.com/doc/articles/enml.php
241+
soup = BeautifulSoup(content, 'html.parser')
260242
ATTR_2_REMOVE = ["id",
261243
"class",
262244
# "on*",
263245
"accesskey",
264246
"data",
265247
"dynsrc",
266-
"tabindex"
267-
]
268-
soup = BeautifulSoup(content, 'html.parser')
248+
"tabindex"]
269249

270250
for tag in soup.findAll():
271251
if hasattr(tag, 'attrs'):
@@ -275,6 +255,7 @@ def textToENML(content, raise_ex=False, format='markdown', rawmd=False):
275255
or k.find('on') == 0])
276256
contentHTML = str(soup)
277257
else:
258+
# Plain text format
278259
contentHTML = Editor.HTMLEscape(content)
279260

280261
tmpstr = ''
@@ -285,21 +266,18 @@ def textToENML(content, raise_ex=False, format='markdown', rawmd=False):
285266
tmpstr = tmpstr + u'<div>' + l + u'</div>'
286267

287268
contentHTML = tmpstr.encode("utf-8")
288-
289-
contentHTML = contentHTML.replace('[x]', '<en-todo checked="true"></en-todo>')
290-
contentHTML = contentHTML.replace('[ ]', '<en-todo></en-todo>')
269+
contentHTML = contentHTML.replace('[x]', '<en-todo checked="true"></en-todo>')
270+
contentHTML = contentHTML.replace('[ ]', '<en-todo></en-todo>')
291271

292272
return Editor.wrapENML(contentHTML)
273+
293274
except:
294275
import traceback
295276
traceback.print_exc()
296277
if raise_ex:
297-
raise Exception("Error while parsing text to html."
298-
" Content must be an UTF-8 encode.")
299-
logging.error("Error while parsing text to html. "
300-
"Content must be an UTF-8 encode.")
301-
out.failureMessage("Error while parsing text to html. "
302-
"Content must be an UTF-8 encode.")
278+
raise Exception("Error while parsing text to html.")
279+
logging.error("Error while parsing text to html.")
280+
out.failureMessage("Error while parsing text to html.")
303281
return tools.exitErr()
304282

305283
def __init__(self, editor, content, noteExtension, raw=False):

tests/test_editor.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,25 @@ def setUp(self):
1818
**Line 3**
1919
2020
"""
21-
self.HTML_TEXT = "<h1>Header 1</h1><h2>Header 2</h2><p>Line 1</p><p>"\
22-
"<em>Line 2</em></p><p><strong>Line 3</strong></p>"
21+
self.HTML_TEXT = """<h1>Header 1</h1>
22+
<h2>Header 2</h2>
23+
<p>Line 1</p>
24+
<p><em>Line 2</em></p>
25+
<p><strong>Line 3</strong></p>
26+
"""
2327

2428
def test_TextToENML(self):
25-
self.assertEqual(Editor.textToENML(self.MD_TEXT).replace('\n', ''),
26-
Editor.wrapENML(self.HTML_TEXT).replace('\n', ''))
29+
self.assertEqual(Editor.textToENML(self.MD_TEXT),
30+
Editor.wrapENML(self.HTML_TEXT))
2731

2832
def test_ENMLToText(self):
2933
wrapped = Editor.wrapENML(self.HTML_TEXT)
3034
self.assertEqual(Editor.ENMLtoText(wrapped), self.MD_TEXT)
3135

36+
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"))
39+
3240
def test_htmlEscape(self):
3341
wrapped = Editor.textToENML(content="<what ever>", format="markdown")
3442
self.assertEqual(wrapped, """<?xml version="1.0" encoding="UTF-8"?>

tests/test_sandbox.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from geeknote.oauth import GeekNoteAuth
77
from random import SystemRandom
88
from string import hexdigits
9-
#from proxyenv.proxyenv import ProxyFactory
9+
if config.DEV_MODE:
10+
from proxyenv.proxyenv import ProxyFactory
1011

1112

1213
# see https://docs.python.org/2.7/library/unittest.html §25.3.6

0 commit comments

Comments
 (0)