Created
December 21, 2013 08:54
-
-
Save patrickwelker/8067056 to your computer and use it in GitHub Desktop.
A script for Martin Kopischke's old version of the Evernote to Markdown conversion script. See: <http://nsuserview.kopischke.net/post/6223792409/i-can-has-some-markdown>
This file contains 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
#!/usr/bin/env bash | |
fillText(){ | |
echo "Notebook: ${1}" | |
echo "Title: ${2}" | |
echo "Url: ${3}" | |
echo "Keywords: ${4}" | |
echo | |
echo "## [∞ Permalink](${3})" | |
echo "## [➡︎ Safari](launchpro://?url=${3})" | |
echo "## [➡︎ Google Chrome](googlechrome-x-callback://x-callback-url/open/?url=${3})" | |
echo "## [➡︎ Copy MD Link](drafts://x-callback-url/create?text=%5B${5}%5D%28${3}%29&action=Copy%20to%20Clipboard&afterSuccess=Delete&x-success=evernote%3A%2F%2F)" | |
echo "## [✚ Add to Link List](drafts://x-callback-url/create?text=%5B${5}%5D%28${3}%29&action=EN%20to%20Link%20List)" | |
echo | |
echo "---" | |
echo | |
echo "## [★︎ Pushpin](pushpin://add?url=${3})" | |
echo "## [◉︎ Tweetbot](tweetbot:///post?text=${3}&callback_url={{evernote://}})" | |
echo "## [☰︎ Velocity](velocity://read?url=${3})" | |
echo "## [⚑︎ OmniFocus](drafts://x-callback-url/create?text=Check%20out%20--%20${5}%20%28see%20details%29%0A${3}&action=OmniFocus%20Mail%20Drop&x-success=evernote%3A%2F%2F)" | |
echo "## [❤︎ Instapaper](x-callback-instapaper://x-callback-url/add?url=${3})" | |
} | |
document=~/Desktop/demo-pre2mdevernote.txt | |
notebook="My test notebook" | |
keywords="test, demo" | |
while read line; do | |
# Remove every Markdown lister marker and match content between square brackets to $title | |
title=$(sed 's/^[*-+] *\[\(.*\)\](.*)/\1/' <<< "${line}") | |
# Remove every Markdown lister marker and match content parenthesis to $url | |
url=$(sed 's/^[*-+] *\[.*\](\(.*\))/\1/' <<< "${line}") | |
# Percent encode $title for use in x-callback-url and truncate the newline character | |
encTitle=$(echo "${title}" | perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' | sed 's/%0A$//') | |
# Read whole list line, remove first 3 characters, url encode and remove new line break | |
# mdlink=$(cut -c '3-' | perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' <<< "${line}") | |
# Call function, generate output and pass it on to the Markdown to Evernote converter | |
fillText "${notebook}" "${title}" "${url}" "${keywords}" "${encTitle}" "${mdlink}" | markdown2evernote.rb | |
done < "${document}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment