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

Edit notebook of existing note #27

Open
wants to merge 2 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
doc/tags
doc/tags-ja
5 changes: 5 additions & 0 deletions autoload/evervim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ function! evervim#markdownBufSetup() " {{{
syn keyword evervimTagWord Tags contained
hi link evervimTagBase Statement
hi link evervimTagWord Type

syn match evervimNotebook '^Notebook:.*$' contains=evervimNotebookWord
syn keyword evervimNotebookWord Notebook contained
hi link evervimNotebook Statement
hi link evervimNotebookWord Type
endfunction
"}}}

Expand Down
13 changes: 13 additions & 0 deletions plugin/py/evernoteapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ def updateNote(self, note): # {{{
return self.__getNoteStore().updateNote(authToken, note)
#}}}

def editNotebook(self, note, localNotebookName):
"""
return note editted notebook
"""
remoteNotebookList = self.listNotebooks()

for remoteNotebook in remoteNotebookList:
if localNotebookName == remoteNotebook.name:
note.notebookGuid = remoteNotebook.guid

return note

def editTag(self, note, tags): # {{{
"""
return note editted tag.
Expand Down Expand Up @@ -90,6 +102,7 @@ def getNote(self, note): # {{{
withResourcesRecognition=False,
withResourcesAlternateData=False)
returnNote.tagNames = self.__getNoteStore().getNoteTagNames(authToken, note.guid)
returnNote.notebookName = self.__getNoteStore().getNotebook(authToken, note.notebookGuid).name
return returnNote
#}}}

Expand Down
12 changes: 8 additions & 4 deletions plugin/py/evervim_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def setAPI(self):

def note2buffer(self, note):
""" return strings array for buffer from note. """
""" note has attribute title, tagNames, content """
""" note has attribute title, tagNames, content, notebookName """
bufStrings = []
pref = EvervimPref.getInstance()
doc = minidom.parseString(note.content)
Expand All @@ -68,27 +68,31 @@ def note2buffer(self, note):
if pref.usemarkdown == '0':
bufStrings.append(note.title)
bufStrings.append("Tags:" + ",".join(note.tagNames))
bufStrings.append('Notebook:' + note.notebookName)
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("Tags:" + ",".join(note.tagNames))
bufStrings.append('Notebook:' + note.notebookName)
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, tags, content, notebook 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 = self.api.editNotebook(note, buflines[2].replace('Notebook:', ''))
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:]))
note = self.api.editNotebook(note, buflines[2].replace('Notebook:', ''))
parsedContent = markdownAndENML.parseMarkdown("\n".join(buflines[3:]))
note.content = EvernoteAPI.NOTECONTENT_HEADER + parsedContent.encode('utf-8') + EvernoteAPI.NOTECONTENT_FOOTER

return note