Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

English Text Updates #36

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# evervim.vim

## description:
edit evernote on vim.
Search, create, and edit notes on Evernote in vim!

## requires:
* python
Expand Down
3 changes: 2 additions & 1 deletion autoload/evervim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ function! evervim#createNoteBuf() " {{{

" clear buffer
call append(0, "")
call append(1, "Tags:")
call append(1, "Notebook:")
call append(2, "Tags:")
call cursor(1,0)
setlocal nomodified

Expand Down
99 changes: 53 additions & 46 deletions doc/evervim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,63 @@ Changelog |evervim-changelog|
==============================================================================
INTRODUCTION *evervim-introduction*

*evervim* (or *evervim.vim* ) is plugin for edit evernote(http://www.evernote.com)
on vim. This plugin can edit evernote by markdown or law XML.
See |:g:evervim_usemarkdown| .
*evervim* (or *evervim.vim* ) is plugin for editing
evernote(http://www.evernote.com) on vim. This plugin can edit evernote by
markdown or raw XML. See |:g:evervim_usemarkdown| .

==============================================================================
REQUIRES *evervim-requires*

Python and vim with compiled +python and "markdown" package for python.
Check Python is enable or not,
To check if Python is enabled or not,
>
:echo has('python')
<
When display '1', then python is enable.
check "markdown" package is installed,
When the result is '1', then python is enabled.
To check whether the "markdown" package is installed,
>
:python import markdown
<
When no error occured, markdown is already installed.
How to install markdown, see below url.
When no error occurs, markdown is already installed.
To install markdown, see the following url:
http://packages.python.org/Markdown/install.html

==============================================================================
INSTALL *evervim-install*

Install files into Vim script directory.

Get "Developer Tokens" from Evernote Web(https://www.evernote.com/api/DeveloperToken.action)
and set g:evervim_devtoken, evervim will initialize on start VIM.
Get "Developer Tokens" from Evernote Web
(https://www.evernote.com/api/DeveloperToken.action) and set
g:evervim_devtoken. Evervim will initialize on VIM startup.

vimrc example:
let g:evervim_devtoken='S=s999:U=9ee99c9:E=999d9999c99:C=99a99a99999:P=9cd:A=en-devtoken:H=cd99999de9999c99b999d99d999cb9f9'

Initialize is not yet, set g:evervim_devtoken and do
After setting g:evervim_devtoken, use this command:
>
:EvervimSetup
<
command, initialize evervim.
(after initialized, added some command for evervim)
to initialize evervim. You only need to do this once (or if you change the
devtoken). Once initialized, the Evervim commands will be available.

==============================================================================
USAGE *evervim-usage*
Display NotebookList
>
:EvervimNotebookList
<
NotebookList is displayed, choice one and <CR>,
notes in notebook will be listed.
choice one and <CR> too, the note will be displayd.
The NotebookList is displayed; choose one and <CR>,
and a split with notes in the selected notebook will be shown.
Choose one and <CR>; the note will be displayed.

Note is formatted
A Note is formatted as follows:
1 line is Title
2 line is Tags (comma deliminated)
3 line after body
2 line is Notebook (when empty the default notebook is used)
3 line is Tags (comma deliminated)
4 line after body

If OpenBrowser plugin installed, you can open note on browser.
If the OpenBrowser plugin installed, you can open the note in your browser.
(http://www.vim.org/scripts/script.php?script_id=3133)
see |:EvervimOpenBrowser|.
==============================================================================
Expand Down Expand Up @@ -106,83 +108,88 @@ COMMAND *evervim-commands*

:EvervimCreateNote *:EvervimCreateNote*
Open new buffer to edit new note.
when buffer saved, note is saved on evernote.
When the buffer is written, note is saved on evernote.

:EvervimOpenBrowser *:EvervimOpenBrowser*
Open note on your browser. Use this command when open single
note or set cursor on notes list.
This command is defined only "OpenBrowser" plugin is installed.
Open note in your browser. Use this command from a buffer
containing a single note or on a selected note in a notes list.
This command is defined only if "OpenBrowser" plugin is installed.
(http://www.vim.org/scripts/script.php?script_id=3133)

:EvervimOpenClient *:EvervimOpenClient*
Open note on your windows client.
This command is defined only vim on windows.
Open note in your windows client.
This command is defined only for VIM on windows.

:EvervimSetup *:EvervimSetup*
Setup acccount.

:EvervimReloadPref *:EvervimReloadPref*
Reload variables. Generally, It will be not used.
Reload variables. Generally, should not be used.
------------------------------------------------------------------------------
variables *evervim-variables*

g:evervim_devtoken *g:evervim_devtoken*
It is "Developer Tokens" string to get from Evernote Web at below.
The "Developer Token" string from Evernote Web at below.
https://www.evernote.com/api/DeveloperToken.action

Default is empty string.
Default is empty string.

g:evervim_workdir *g:evervim_workdir*
Work directory.

Default is $HOME/.evervim

g:evervim_usemarkdown *g:evervim_usemarkdown*
Edit note on markdown or XML.
Edit note in markdown or XML.

** WARNNING: Markdown format is not keep design tags.
If you open already edited note (not evervim ex:web clipped note)
and save it on evervim, the design tags will be loss. **
** WARNING: Markdown format does not preserve design tags. If
you open already an existing note (not created with evervim, i.e. a
web-clipped note) and save it in evervim, the design tags will be lost. **

defalult is '1'. It means use markdown.
Default is '1'. It means use markdown.

g:evervim_sortbooks *g:evervim_sortnotebooks*
Sort pattern of notebooks. It can use below values.
(name | serviceCreated | serviceUpdated) (asc | desc)

Default is 'name asc'.
It means name desc.
It means the list is sorted by name in ascending (A-Z) order.

g:evervim_sorttags *g:evervim_sorttags*
Sort pattern of tags. It can use below values.
(name) (asc | desc)

Default is 'name asc'.
It means name desc.
It means the tags are sorted by name in ascending (A-Z) order

g:evervim_xmlindent *g:evervim_xmlindent*
When you edit note on XML, indent of XML.
When you edit a note in XML, use this string for each indent of the XML.

Default is ' '.

g:evervim_asyncupdate *g:evervim_asyncupdate*
This value means When save note,
asynchronous update to evernote or not.
This value enables or disables asynchronous update to evernote
when saving notes.

Default is '0'. It means not asynchronous update.
Asynchronous update is not runnning multi.
So if one thread runnning, not update to evernote.
Next timing of saving buffer, update to evernote.
Default is '0', or synchronous updates.
NOTE: With asynchronous updates on, Evervim will not perform
multiple updates simultaneously; if one update thread is
already runnning, Evervim will skip the update to Evernote.
You will need to write the buffer again to update the buffer on Evernote.

g:evervim_splitoption *g:evervim_splitoption*
Open ListWindowmode, if
let g:evervim_splitoption=''
open listwindow horizontal.
Evervim will open listwindows using a horizontal split.

Default is 'v'. It means open vertical.
Default is 'v'. It means open list windows using vertical
splits.

g:evervim_defaultnotebook
Contains the name of the default notebook. If no notebook is
specified when a note is created, the note is saved to this
notebook.

Edit note on markdown or XML.

==============================================================================
TODO *evervim-todo*
Expand Down
28 changes: 22 additions & 6 deletions plugin/py/evervim_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self):
self.encoding = None
self.asyncupdate = None
self.enscriptpath = None
self.defaultnotebook = None

@classmethod
def getInstance(self):
Expand Down Expand Up @@ -59,36 +60,51 @@ def setAPI(self):

def note2buffer(self, note):
""" return strings array for buffer from note. """
""" note has attribute title, tagNames, content """
""" note has attribute title, notebook, tagNames, content """
bufStrings = []
pref = EvervimPref.getInstance()
doc = minidom.parseString(note.content)
ennote = doc.getElementsByTagName("en-note")[0]

notebooks = self.api.listNotebooks()
notebook = next((n for n in notebooks if n.guid == note.notebookGuid), None)
notebookName = notebook.name if notebook is not None else ""

if pref.usemarkdown == '0':
bufStrings.append(note.title)
bufStrings.append("Notebook:" + notebookName)
bufStrings.append("Tags:" + ",".join(note.tagNames))
contentxml = ennote.toprettyxml(indent=pref.xmlindent, encoding='utf-8')
contentxml = re.sub('^' + pref.xmlindent, '', contentxml, flags=re.MULTILINE)
bufStrings.extend([line for line in contentxml.splitlines()[1:-1] if line.strip()])
else:
bufStrings.append('# ' + note.title)
bufStrings.append("Notebook:" + notebookName)
bufStrings.append("Tags:" + ",".join(note.tagNames))
content = markdownAndENML.parseENML(ennote).encode('utf-8')
bufStrings.extend(content.splitlines())
return bufStrings

def buffer2note(self, note, buflines):
""" return note that set title, tags, content from buftext """
""" return note that set title, notebook, tags, content from buftext """
pref = EvervimPref.getInstance()
if pref.usemarkdown == '0':
note.title = buflines[0]
note = self.api.editTag(note, buflines[1].replace('Tags:', ''))
note.content = EvernoteAPI.NOTECONTENT_HEADER + "\n".join(buflines[2:]) + EvernoteAPI.NOTECONTENT_FOOTER
note.content = EvernoteAPI.NOTECONTENT_HEADER + "\n".join(buflines[3:]) + EvernoteAPI.NOTECONTENT_FOOTER
else:
note.title = re.sub(r'^#', '',buflines[0]).strip()
note = self.api.editTag(note, buflines[1].replace('Tags:', ''))
parsedContent = markdownAndENML.parseMarkdown("\n".join(buflines[2:]))
parsedContent = markdownAndENML.parseMarkdown("\n".join(buflines[3:]))
note.content = EvernoteAPI.NOTECONTENT_HEADER + parsedContent.encode('utf-8') + EvernoteAPI.NOTECONTENT_FOOTER

notebookName = buflines[1].replace('Notebook:', '').strip()
if notebookName == "" and pref.defaultnotebook is not None:
notebookName = pref.defaultnotebook

notebooks = self.api.listNotebooks()
notebook = next((n for n in notebooks if n.name == notebookName), None)
if notebook is not None:
note.notebookGuid = notebook.guid

note = self.api.editTag(note, buflines[2].replace('Tags:', ''))

return note
20 changes: 10 additions & 10 deletions plugin/py/evervim_editor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ def testNote2buffer(self): # {{{
EvervimPref.getInstance().xmlindent = ' ' # default ts=4
xmlStrings = editor.note2buffer(note)
self.assertEqual(u'タイトルテスト'.encode('utf-8'), xmlStrings[0])
self.assertEqual(u'Tags:タグ1,*タグ2'.encode('utf-8'), xmlStrings[1])
self.assertEqual('this is content'.encode('utf-8'), xmlStrings[2]) # this is content
self.assertEqual('本文テスト'.encode('utf-8'), xmlStrings[3]) # 本文テスト
self.assertEqual('<h3>'.encode('utf-8'), xmlStrings[4]) # <h3>
self.assertEqual(' たぐ3'.encode('utf-8'), xmlStrings[5]) # たぐ3
self.assertEqual('</h3>'.encode('utf-8'), xmlStrings[6]) # </h3>
self.assertEqual(u'Tags:タグ1,*タグ2'.encode('utf-8'), xmlStrings[2])
self.assertEqual('this is content'.encode('utf-8'), xmlStrings[3]) # this is content
self.assertEqual('本文テスト'.encode('utf-8'), xmlStrings[4]) # 本文テスト
self.assertEqual('<h3>'.encode('utf-8'), xmlStrings[5]) # <h3>
self.assertEqual(' たぐ3'.encode('utf-8'), xmlStrings[6]) # たぐ3
self.assertEqual('</h3>'.encode('utf-8'), xmlStrings[7]) # </h3>

EvervimPref.getInstance().usemarkdown = '1' # dont use markdown
mkdStrings = editor.note2buffer(note)
self.assertEqual(u'# タイトルテスト'.encode('utf-8'), mkdStrings[0])
self.assertEqual(u'Tags:タグ1,*タグ2'.encode('utf-8'), xmlStrings[1])
self.assertEqual('this is content'.encode('utf-8'), mkdStrings[2])
self.assertEqual('本文テスト'.encode('utf-8'), mkdStrings[3])
self.assertEqual('### たぐ3'.encode('utf-8'), mkdStrings[4])
self.assertEqual(u'Tags:タグ1,*タグ2'.encode('utf-8'), xmlStrings[2])
self.assertEqual('this is content'.encode('utf-8'), mkdStrings[3])
self.assertEqual('本文テスト'.encode('utf-8'), mkdStrings[4])
self.assertEqual('### たぐ3'.encode('utf-8'), mkdStrings[5])
# }}}

def testBuffer2note(self): # {{{
Expand Down
1 change: 1 addition & 0 deletions plugin/py/evervimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def setPref(self): # {{{
self.pref.asyncupdate = vim.eval("g:evervim_asyncupdate")
self.pref.encoding = vim.eval('&enc')
self.pref.enscriptpath = None
self.pref.defaultnotebook = vim.eval("g:evervim_defaultnotebook")
# }}}

def setAPI(self): # {{{
Expand Down
33 changes: 31 additions & 2 deletions plugin/py/markdownAndENML.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@
import markdown
import xml.sax.saxutils
import re
from markdown.extensions import Extension
from markdown.inlinepatterns import Pattern
from markdown.util import etree
import logging

TODOPATTERN= r'\[(X| )\]'
class ENMLToDoPattern(Pattern):

def handleMatch(self, m):
el = etree.Element("en-todo")
logging.debug("Groups: {}".format(m.groups()))
if m.group(2) == 'X':
el.set("checked", "true")
return el


class ENMLExtension(Extension):

def extendMarkdown(self, md, md_globals):

md.inlinePatterns.add(
'enml', ENMLToDoPattern(TODOPATTERN), "<linebreak" )

class parserOption: # {{{
def __init__(self):
Expand Down Expand Up @@ -100,7 +121,14 @@ def parseENML(node, level=0, result='', option=parserOption()): # {{{
result += "".join([parseENML(child, level + 1, "", option) for child in node.childNodes])
result += "\n"
option.blockquote -= 1
elif tag in ["img", "en-media", "en-todo", "en-crypt"]: # 後で改行を除去して見やすくする?
elif tag == "en-todo":
result += "["
if node.getAttribute("checked") == "true":
result += "X"
else:
result += " "
result += "] "
elif tag in ["img", "en-media", "en-crypt"]: # 後で改行を除去して見やすくする?
return node.toxml() + "\n"
elif tag in ["h1", "h2", "h3", "h4", "h5", "h6"]:
headerlv = tag[1:]
Expand All @@ -121,7 +149,8 @@ def parseENML(node, level=0, result='', option=parserOption()): # {{{


def parseMarkdown(mkdtext): # {{{
m = markdown.markdown(mkdtext.decode('utf-8'))
m = markdown.markdown(mkdtext.decode('utf-8'), extensions=[ENMLExtension()])
logging.debug(m)
return m
#}}}

Expand Down
Loading