LoginSignup
11
11

More than 5 years have passed since last update.

Evernoteでmadeverでmarkdown、但しmdソースは温存

Last updated at Posted at 2012-11-22

これは何

ノートブック markdown.src に含まれる新しいソースをmarkdownし、ノートブック markdown.html にセーブするスクリプト

markdownにはmadeverを使用

madever はmdソースを変換後のhtmlで上書きするが、このスクリプトはソースをソース専用ノートブックに温存したまま、マークダウン結果を結果専用ノートブックに生成する

madeverではpandocによるマークダウンに失敗するとソースが消滅してしまうという欠点があるのでその回避のためソースノートと生成ノートを分離したかったのがこのスクリプトを書いた主目的

todo

  • pandoc非依存にしたい
  • GitHub Flavored Markdown版を作りたい

スクリプト

AppleScriptエディタで、以下のソースを$HOME/Library/Scripts/evernote_markdown.scptとして保存

property src_notebook : "markdown.src"property dest_notebook : "markdown.html"global madeverglobal CSSset 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 tellend markdowntell 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```
11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11