Example #1
0
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)
Example #2
0
    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))
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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))
Example #6
0
    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))
Example #7
0
    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))
Example #8
0
    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')
Example #9
0
    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))
Example #10
0
    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')
Example #11
0
    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'])
Example #12
0
    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'])
Example #13
0
    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))
Example #14
0
    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))
Example #15
0
    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))
Example #16
0
    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))
Example #17
0
    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))
Example #18
0
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)
Example #19
0
    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')
Example #20
0
    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')
Example #21
0
    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))
Example #22
0
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)
Example #23
0
    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))
Example #24
0
 def test_get_note_assets_path(self):
     note = Note('/foo/bar/my note.md')
     self.assertEqual(note.assets, '/foo/bar/assets/my note/')
Example #25
0
    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')
Example #26
0
 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')
Example #27
0
 def test_plaintext_markdown(self):
     note = Note(_path('my note.md'))
     self.assertEqual(note.plaintext, 'HEY HI\nfoo bar qua')
Example #28
0
 def test_content_pdf(self):
     note = Note(_path('womp.pdf'))
     self.assertEqual(note.content, 'I\'m a PDF')
Example #29
0
 def test_get_note_resources_path(self):
     note = Note('/foo/bar/my note.md')
     self.assertEqual(note.resources, '/foo/bar/_resources/my note/')