Create a gist now

Instantly share code, notes, and snippets.

@kkajita /
Last active Dec 29, 2015

What would you like to do?
EvernoteにMarkdown形式で記述した文書をMardedでプレビューするためのMac OS X用スクリプト。 先頭のUSER_NAMEにEvernoteのユーザ名を記入してください。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import codecs
import html2text
APP_NAME = "Marked"
HOME = os.environ['HOME']
content_dir = "%(HOME)s/Library/Containers/com.evernote.Evernote/Data/Library/Application Support/Evernote/accounts/Evernote/%(USER_NAME)s/content" % locals()
last_dir = sorted([os.path.join(content_dir, f) for f in os.listdir(content_dir)],
html_file = os.path.join(last_dir, 'content.html')
md_file = os.path.join(last_dir, '')
with, 'r', 'utf-8') as html:
with, 'w', 'utf-8') as md:
h = html2text.HTML2Text()
h.body_width = None
text = h.handle(
# remove unnecessary newline or whitespace characters
text = text.replace(u'\u00A0', u' ')
text = text.replace(u'\n\n', u'\n')
text = text.replace(u' \n\n', u'\n')
# launch Markdown viewer app.; mac os x only
os.popen("""osascript -e \
'tell application \"Marked\"
open \"%s\"
end tell'""" % (md_file,))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment