Created
November 22, 2012 16:57
-
-
Save naoyat/4132107 to your computer and use it in GitHub Desktop.
Evernoteでmadeverでmarkdown、但しmdソースは温存 ref: http://qiita.com/items/1dfb0e0ff7ac6b1bb2bd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property src_notebook : "markdown.src" | |
property dest_notebook : "markdown.html" | |
global madever | |
global CSS | |
set madever_dir to (path to scripts folder from user domain as text) & "madever" | |
set madever to load script file (madever_dir & ":madever.scpt") | |
set loadtheme to load script file (madever_dir & ":loadtheme.scpt") | |
set CSS to loadtheme's main() | |
on markdown(srcNote, destNote) | |
tell application "Evernote" | |
set accountname to current account's name as text | |
set noteid to madever's split(srcNote's local id, "/")'s last item as text | |
set contentAlias to (((path to application support from user domain) as text) & "Evernote:accounts:Evernote:" & accountname & ":content:" & noteid & ":content.html") as alias | |
set contentPath to contentAlias's POSIX path | |
set pandoc to madever's findPandoc() | |
set cmd to "textutil -convert txt -stdout \"" & contentPath & "\" | " & pandoc & " -S --email-obfuscation=none -f markdown -t html" | |
set renderedBody to do shell script cmd | |
set renderedBody to madever's subHtml(renderedBody) | |
set bodycss to madever's value_of(CSS, "body") | |
set renderedHtml to "<html><body style=\"" & bodycss & "\">" & renderedBody & "</body></html>" | |
if destNote = null then | |
set newNote to (create note with html renderedHtml ¬ | |
title (srcNote's title) ¬ | |
notebook dest_notebook ¬ | |
tags (srcNote's tags) ¬ | |
created srcNote's creation date) | |
set newNote's modification date to srcNote's modification date | |
else | |
set destNote's title to srcNote's title | |
set destNote's HTML content to renderedHtml | |
set destNote's tags to srcNote's tags | |
set destNote's modification date to srcNote's modification date | |
end if | |
end tell | |
end markdown | |
tell application "Evernote" | |
-- 最後にmarkdownした日時を得る | |
set last_updated to (current date) - 86400 | |
repeat with destNote in (find notes "notebook:" & dest_notebook) | |
set mdate to destNote's modification date | |
if mdate > last_updated then | |
set last_updated to mdate | |
end if | |
end repeat | |
-- last_updated より新しいソースをmarkdown | |
repeat with srcNote in (find notes "notebook:" & src_notebook) | |
-- & " intitle:\"" & 1 & "\"") | |
if srcNote's modification date > last_updated then | |
set destNote to null | |
repeat with dupNote in (find notes "notebook:" & dest_notebook & " intitle:\"" & (srcNote's title) & "\"") | |
if dupNote's creation date = srcNote's creation date then | |
set destNote to dupNote | |
end if | |
end repeat | |
my markdown(srcNote, destNote) | |
end if | |
end repeat | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment