Esempio n. 1
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. 2
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. 3
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. 4
0
 def test_ENMLToText(self):
     wrapped = Editor.wrapENML(self.HTML_TEXT)
     self.assertEqual(Editor.ENMLtoText(wrapped), self.MD_TEXT)