Esempio n. 1
0
    def test_TODO(self):
        MD_TODO = "\n* [ ]item 1\n\n* [x]item 2\n\n* [ ]item 3\n\n"
        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"
        self.assertEqual(Editor.textToENML(MD_TODO),
                         Editor.wrapENML(HTML_TODO))

        wrapped = Editor.wrapENML(HTML_TODO)
        text = Editor.ENMLtoText(wrapped)
        self.assertEqual(text, MD_TODO)
Esempio n. 2
0
    def test_htmlEscape(self):
        wrapped = Editor.textToENML(content="<what ever>", format="markdown")
        self.assertEqual(
            wrapped, """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note><p>&lt;what ever&gt;</p>
</en-note>""")
Esempio n. 3
0
def ENMLtoText(contentENML):
    format = 'vim-default'
    if int(vim.eval('exists("g:GeeknoteFormat")')):
        format = vim.eval('g:GeeknoteFormat')

    if format == 'pre':
        print 'WARNING: g:GeeknoteFormat=pre is deprecated.'

    if format == 'vim-default' or format == 'pre':
        try:
            soup = BeautifulSoup(contentENML.decode('utf-8'))
            sections = soup.select('pre')
            if len(sections) >= 1:
                content = ''
                for c in sections[0].contents:
                    content = u''.join((content, c))
                content = re.sub(r' *\n', os.linesep, content)
                content = content.replace('&lt;', '<')
                content = content.replace('&gt;', '>')
                content = content.replace('&amp;', '&')
                return content.encode('utf-8')
        except:
            pass
            # fall-through
    return Editor.ENMLtoText(contentENML)
Esempio n. 4
0
 def do_test_editWithEditorInThread(self, txt, expected):
     testNote = tools.Struct(title="note title", content=txt)
     # hack to make updateNote work - see above
     testNote.guid = testNote
     testData = self.notes._parseInput("title", txt, "tag1, tag2", None,
                                       testNote)
     result = self.notes._editWithEditorInThread(testData, testNote)
     self.assertEqual(Editor.ENMLtoText(testNote.content), expected)
Esempio n. 5
0
    def test_not_checklist(self):
        wrapped = Editor.textToENML(content=" Item head[0]; ",
                                    format="markdown")
        self.assertEqual(
            wrapped, """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note><p>Item head[0]; </p>
</en-note>""")
Esempio n. 6
0
    def test_parceInput1(self):
        testData = self.notes._parceInput("title", "test body", "tag1")
        self.assertTrue(isinstance(testData, dict))
        if not isinstance(testData, dict):
            return

        self.assertEqual(testData['title'], "title")
        self.assertEqual(testData['content'], Editor.textToENML("test body"))
        self.assertEqual(testData["tags"], ["tag1", ])
Esempio n. 7
0
def textToENML(content):
    format = 'vim-default'
    if int(vim.eval('exists("g:GeeknoteFormat")')):
        format = vim.eval('g:GeeknoteFormat')

    if format == 'pre':
        print 'WARNING: g:GeeknoteFormat=pre is deprecated.'

    if format != 'vim-default' and format != 'pre':
        return Editor.textToENML(content, True, format) 

    content = content.replace('<', '&lt;')
    content = content.replace('>', '&gt;')
    content = content.replace('&', '&amp;')
    content = unicode(content, "utf-8")
    contentHTML = u''.join(('<pre>', content, '</pre>')).encode("utf-8")

    enml = Editor.wrapENML(contentHTML)
    return enml
Esempio n. 8
0
def textToENML(content):
    format = 'vim-default'
    if int(vim.eval('exists("g:GeeknoteFormat")')):
        format = vim.eval('g:GeeknoteFormat')

    if format == 'pre':
        print 'WARNING: g:GeeknoteFormat=pre is deprecated.'

    if format != 'vim-default' and format != 'pre':
        return Editor.textToENML(content, True, format) 

    content = content.replace('<', '&lt;')
    content = content.replace('>', '&gt;')
    content = content.replace('&', '&amp;')
    content = unicode(content, "utf-8")
    contentHTML = u''.join(('<pre>', content, '</pre>')).encode("utf-8")

    enml = Editor.wrapENML(contentHTML)
    return enml
Esempio n. 9
0
    def _parseInput(self,
                    title=None,
                    content=None,
                    tags=None,
                    notebook=None,
                    resources=None,
                    note=None):
        result = {
            "title": title,
            "content": content,
            "tags": tags,
            "notebook": notebook,
            "resources": resources,
        }
        result = tools.strip(result)

        # if get note without params
        if note and title is None and content is None and tags is None and notebook is None:
            content = config.EDITOR_OPEN

        if title is None and note:
            result['title'] = note.title

        if content:
            content = Editor.textToENML(content, format='other')
            result['content'] = content
            '''
            if content != config.EDITOR_OPEN:
                if isinstance(content, str) and os.path.isfile(content):
                    logging.debug("Load content from the file")
                    content = open(content, "r").read()

                logging.debug("Convert content")
            '''

        if tags:
            result['tags'] = tools.strip(tags.split(','))

        if notebook:
            #notepadGuid = Notebooks().getNoteGUID(notebook)
            notepadGuid = self.getNoteGUID(notebook)
            if notepadGuid is None:
                #newNotepad = Notebooks().create(notebook)
                newNotepad = self.create(notebook)
                notepadGuid = newNotepad.guid

            result['notebook'] = notepadGuid
            logging.debug("Search notebook")

        return result
Esempio n. 10
0
    def _parseInput(self, title=None, content=None, tags=None, notebook=None, resources=None, note=None):
        result = {
            "title": title,
            "content": content,
            "tags": tags,
            "notebook": notebook,
            "resources": resources,
        }
        result = tools.strip(result)

        # if get note without params
        if note and title is None and content is None and tags is None and notebook is None:
            content = config.EDITOR_OPEN

        if title is None and note:
            result['title'] = note.title

        if content:
            content = Editor.textToENML(content,format='other')
            result['content'] = content
            '''
            if content != config.EDITOR_OPEN:
                if isinstance(content, str) and os.path.isfile(content):
                    logging.debug("Load content from the file")
                    content = open(content, "r").read()

                logging.debug("Convert content")
            '''

        if tags:
            result['tags'] = tools.strip(tags.split(','))

        if notebook:
            #notepadGuid = Notebooks().getNoteGUID(notebook)
            notepadGuid = self.getNoteGUID(notebook)
            if notepadGuid is None:
                #newNotepad = Notebooks().create(notebook)
                newNotepad = self.create(notebook)
                notepadGuid = newNotepad.guid

            result['notebook'] = notepadGuid
            logging.debug("Search notebook")

        return result
Esempio n. 11
0
 def test_TextToENML(self):
     self.assertEqual(Editor.textToENML(self.MD_TEXT).replace('\n', ''),
                      Editor.wrapENML(self.HTML_TEXT).replace('\n', ''))
Esempio n. 12
0
    def test_wrapENML_success(self):
        text = "test"
        result = '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>test</en-note>'''
        self.assertEqual(Editor.wrapENML(text), result)
Esempio n. 13
0
 def test_TODO(self):
     self.assertEqual(Editor.textToENML("- [ ] item 1\n- [x] item 2\n- [ ] item 3"),
                      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"))
Esempio n. 14
0
 def test_TextToENML(self):
     self.assertEqual(
         Editor.textToENML(self.MD_TEXT).replace('\n', ''),
         Editor.wrapENML(self.HTML_TEXT).replace('\n', ''))
Esempio n. 15
0
 def test_TODO(self):
     self.assertEqual(
         Editor.textToENML("- [ ] item 1\n- [x] item 2\n- [ ] item 3"),
         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"
         ))
Esempio n. 16
0
 def test_TextToENML(self):
     self.assertEqual(Editor.textToENML(self.MD_TEXT),
                      Editor.wrapENML(self.HTML_TEXT))
Esempio n. 17
0
    def test_not_checklist(self):
        wrapped = Editor.textToENML(content=" Item head[0]; ", format="markdown")
        self.assertEqual(wrapped, """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note><p>Item head[0]; </p>
</en-note>""")
Esempio n. 18
0
 def test_ENMLToText(self):
     wrapped = Editor.wrapENML(self.HTML_TEXT)
     self.assertEqual(Editor.ENMLtoText(wrapped), self.MD_TEXT)
Esempio n. 19
0
    def test_htmlEscape(self):
        wrapped = Editor.textToENML(content="<what ever>", format="markdown")
        self.assertEqual(wrapped, """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note><p>&lt;what ever&gt;</p>
</en-note>""")
Esempio n. 20
0
 def test_TextToENML(self):
     self.assertEqual(Editor.textToENML(self.MD_TEXT),
                      Editor.wrapENML(self.HTML_TEXT))
Esempio n. 21
0
    def test_wrapENML_success(self):
        text = "test"
        result = '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
<en-note>test</en-note>'''
        self.assertEqual(Editor.wrapENML(text), result)
Esempio n. 22
0
 def test_ENMLToText(self):
     wrapped = Editor.wrapENML(self.HTML_TEXT)
     self.assertEqual(Editor.ENMLtoText(wrapped), self.MD_TEXT)