Skip to content

Instantly share code, notes, and snippets.

@kkajita
Last active December 29, 2015 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkajita/7685019 to your computer and use it in GitHub Desktop.
Save kkajita/7685019 to your computer and use it in GitHub Desktop.
EvernoteにMarkdown形式で記述した文書をMardedでプレビューするためのMac OS X用スクリプト。 先頭のUSER_NAMEにEvernoteのユーザ名を記入してください。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import codecs
import html2text
USER_NAME = "<EVERNOTE_USER_NAME>"
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)],
key=os.path.getmtime)[-1]
html_file = os.path.join(last_dir, 'content.html')
md_file = os.path.join(last_dir, 'content.md')
with codecs.open(html_file, 'r', 'utf-8') as html:
with codecs.open(md_file, 'w', 'utf-8') as md:
h = html2text.HTML2Text()
h.body_width = None
text = h.handle(html.read())
# 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')
md.write(text)
# launch Markdown viewer app.; mac os x only
os.popen("""osascript -e \
'tell application \"Marked\"
activate
open \"%s\"
end tell'""" % (md_file,))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment