def clip(save, edit, browser, overwrite): """convert html in the clipboard to markdown""" html = clipboard.get_clipboard_html() if html is None: click.echo('No html in the clipboard') return if save is None: content = html2md.html_to_markdown(html).strip() click.echo(content) return if not save.endswith('.md'): click.echo('Note must have extension ".md"') return note = Note(save) if os.path.exists(note.path.abs) and not overwrite: click.echo('Note already exists at "{}" (specify `--overwrite` to overwrite)'.format(note.path.abs)) return html = parsers.rewrite_external_images(html, note) content = html2md.html_to_markdown(html).strip() note.write(content) if browser: click.launch('http://localhost:{0}/{1}'.format(conf.PORT, note.path.rel)) if edit: click.edit(filename=note.path.abs)
def test_clean_note_assets(self): note = Note(_path('my note.md')) note_asset = _path('assets/my note/foo.jpg') self.assertTrue(exists(note_asset)) note.clean_assets(delete=True) self.assertFalse(exists(note_asset))
def test_add_note(self): note = Note(_path('new note.md')) note.write('foobar') self.index.add_note(note) self.assertEqual(self.index.size, self.expected_notes + 1)
def test_on_created(self): note = Note(_path('a new note.md')) note.write('# a new note') e = Event(is_directory=False, src_path=note.path.abs, dest_path=None) self.handler.on_created(e) self.assertTrue(self.nomadic.index.note_at(note.path.rel))
def test_clean_note_resources(self): note = Note(_path('my note.md')) note_resource = _path('_resources/my note/foo.jpg') self.assertTrue(exists(note_resource)) note.clean_resources() self.assertFalse(exists(note_resource))
def test_update_note(self): note = Note(_path('my note.md')) note.write(u'changed note content') self.index.update_note(note) note_ = self.index.note_at(note.path.rel) self.assertTrue(note_) self.assertEqual(note_['content'], u'changed note content')
def test_on_modified(self): note = Note(_path('my note.md')) note.write('a changed note') e = Event(is_directory=False, src_path=note.path.abs, dest_path=None) self.handler.on_modified(e) note = self.nomadic.index.note_at(note.path.rel) self.assertEqual('a changed note', note['content'])
def test_delete_note(self): src = _path('my note.md') src_asset = _path('assets/my note/foo.jpg') self.assertTrue(exists(src)) self.assertTrue(exists(src_asset)) note = Note(src) note.delete() self.assertFalse(exists(src)) self.assertFalse(exists(src_asset))
def test_delete_note(self): src = _path('my note.md') src_resource = _path('_resources/my note/foo.jpg') self.assertTrue(exists(src)) self.assertTrue(exists(src_resource)) note = Note(src) note.delete() self.assertFalse(exists(src)) self.assertFalse(exists(src_resource))
def test_on_moved_directory(self): path = _path('some_notebook') path_new = _path('moved_notebook') shutil.move(path, path_new) e = Event(is_directory=True, src_path=path, dest_path=path_new) self.handler.on_moved(e) old_note = Note(_path('some_notebook/a cool note.md')) self.assertFalse(self.nomadic.index.note_at(old_note.path.rel)) new_note = Note(_path('moved_notebook/a cool note.md')) self.assertTrue(self.nomadic.index.note_at(new_note.path.rel))
def test_on_moved(self): note = Note(_path('my note.md')) note_new = Note(_path('some_notebook/my moved note.md')) self.assertTrue(self.nomadic.index.note_at(note.path.rel)) shutil.move(note.path.abs, note_new.path.abs) e = Event(is_directory=False, src_path=note.path.abs, dest_path=note_new.path.abs) self.handler.on_moved(e) self.assertFalse(self.nomadic.index.note_at(note.path.rel)) self.assertTrue(self.nomadic.index.note_at(note_new.path.rel))
def export(note, outdir, watch): """export a note to html""" # convert to abs path; don't assume we're in the notes folder note = os.path.join(os.getcwd(), note) n = Note(note) f = partial(compile.compile_note, outdir=outdir, templ='default') watch_note(n, f) if watch else f(n)
def test_move_note(self): src = _path('my note.md') dest = _path('some_notebook/my moved note.md') src_asset = _path('assets/my note/foo.jpg') dest_asset = _path('some_notebook/assets/my moved note/foo.jpg') note = Note(src) note.move(dest) self.assertTrue(exists(dest)) self.assertTrue(exists(dest_asset)) self.assertFalse(exists(src)) self.assertFalse(exists(src_asset)) self.assertEquals(note.path.abs, dest) self.assertEquals(note.title, 'my moved note')
def test_move_note(self): src = _path('my note.md') dest = _path('some_notebook/my moved note.md') src_resource = _path('_resources/my note/foo.jpg') dest_resource = _path('some_notebook/_resources/my moved note/foo.jpg') note = Note(src) note.move(dest) self.assertTrue(exists(dest)) self.assertTrue(exists(dest_resource)) self.assertFalse(exists(src)) self.assertFalse(exists(src_resource)) self.assertEquals(note.path.abs, dest) self.assertEquals(note.title, 'my moved note')
def test_on_deleted(self): note = Note(_path('my note.md')) self.assertTrue(self.nomadic.index.note_at(note.path.rel)) os.remove(note.path.abs) e = Event(is_directory=False, src_path=note.path.abs, dest_path=None) self.handler.on_deleted(e) self.assertFalse(self.nomadic.index.note_at(note.path.rel))
def view(note): """view a note in the browser, recompiling when changed""" # convert to abs path; don't assume we're in the notes folder outdir = '/tmp' note = os.path.join(os.getcwd(), note) n = Note(note) compile.compile_note(n, outdir=outdir, templ='default') click.launch('/tmp/{title}/{title}.html'.format(title=n.title)) f = partial(compile.compile_note, outdir=outdir, templ='default') watch_note(n, f)
def test_delete_note(self): note = Note(_path('my note.md')) self.index.delete_note(note) self.assertEqual(self.index.size, self.expected_notes - 1) self.assertTrue(not self.index.note_at(note.path.rel))
def test_get_note_assets_path(self): note = Note('/foo/bar/my note.md') self.assertEqual(note.assets, '/foo/bar/assets/my note/')
def test_initialization(self): note = Note('/foo/bar/my note.md') self.assertEquals(note.title, 'my note') self.assertEquals(note.ext, '.md') self.assertEquals(note.path.abs, '/foo/bar/my note.md')
def test_plaintext_html(self): note = Note(_path('test.html')) self.assertEqual(note.plaintext, 'Test HTML\n\n\n\n\n This is a test')
def test_plaintext_markdown(self): note = Note(_path('my note.md')) self.assertEqual(note.plaintext, 'HEY HI\nfoo bar qua')
def test_content_pdf(self): note = Note(_path('womp.pdf')) self.assertEqual(note.content, 'I\'m a PDF')
def test_get_note_resources_path(self): note = Note('/foo/bar/my note.md') self.assertEqual(note.resources, '/foo/bar/_resources/my note/')