def clip(save, edit, view, overwrite):
"""convert html in the clipboard to markdown"""
path = save
html = get_clipboard_html()
if html is None:
click.echo('No html in the clipboard')
return
if path is None:
content = html2md.html_to_markdown(html).strip()
click.echo(content)
return
if not path.endswith('.md'):
click.echo('Note must have extension ".md"')
return
note = util.abs_path(path)
if os.path.exists(note) and not overwrite:
click.echo('Note already exists at "{}" (specify `--overwrite` to overwrite)'.format(note))
return
html = parsers.rewrite_external_images(html, note)
content = html2md.html_to_markdown(html).strip()
with open(note, 'w') as f:
f.write(content)
if edit:
click.edit(filename=note)
if view:
compile_note(note, '/tmp', view=True)
评论列表
文章目录