Skip to content

Instantly share code, notes, and snippets.

@rashita
Created September 23, 2016 01:18
Show Gist options
  • Save rashita/e2c45d2b7fecdec19f127d9b25de5163 to your computer and use it in GitHub Desktop.
Save rashita/e2c45d2b7fecdec19f127d9b25de5163 to your computer and use it in GitHub Desktop.
Evernoteのノート内にマークダウン式の見出しがあれば、それを対応するhタグに変換する。1〜6まで。
use framework "Foundation"
tell application "Evernote"
set a to selection
repeat with i in a
set r0Note to HTML content of i
set r1Note to my regexReplace(r0Note, "<div>#([^#]*?)</div>", "<h1>$1</h1>")
set r2Note to my regexReplace(r1Note, "<div>##([^#]*?)</div>", "<h2>$1</h2>")
set r3Note to my regexReplace(r2Note, "<div>###([^#]*?)</div>", "<h3>$1</h3>")
set r4Note to my regexReplace(r3Note, "<div>####([^#]*?)</div>", "<h4>$1</h4>")
set r5Note to my regexReplace(r4Note, "<div>#####([^#]*?)</div>", "<h5>$1</h5>")
set r6Note to my regexReplace(r5Note, "<div>######([^#]*?)</div>", "<h6>$1</h6>")
set HTML content of i to r6Note
end repeat
end tell
on regexReplace(aText as text, pattern as text, replacement as text)
--require framework: Foundation
set regularExpression to current application's NSRegularExpression's regularExpressionWithPattern:pattern options:0 |error|:(missing value)
return (regularExpression's stringByReplacingMatchesInString:aText options:0 range:{location:0, |length|:count aText} withTemplate:replacement) as text
end regexReplace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment