Skip to content

Instantly share code, notes, and snippets.

@tomsoderlund
Last active June 3, 2017 04:24
Show Gist options
  • Save tomsoderlund/fd832f5e94518d38a648db926cf32834 to your computer and use it in GitHub Desktop.
Save tomsoderlund/fd832f5e94518d38a648db926cf32834 to your computer and use it in GitHub Desktop.
Convert Evernote notes in HTML to Markdown
#!/usr/bin/env
# Convert Evernote notes in HTML to Markdown
# requires reverse_markdown (https://github.com/xijo/reverse_markdown)
# Preserve timestamp from Evernote
function get_timestamp {
reverse_markdown "$1" | \
sed -n '/<meta name="created" content="/p' | \
sed -e 's/<meta name="created" content="//g' | \
sed -e 's/ +0000">//g' | \
sed -e 's/-//g' | \
sed -e 's/://g' | \
sed -e 's/ //g' | \
cut -c 1-12 | \
cat
}
# Convert HTML to Markdown
function convert_evernote_html_to_markdown {
# New name .md
newName=markdown/${1%%.html}.md
echo $newName
# Convert to Markdown
reverse_markdown "$1" | \
sed -e 's/<title>/# /g' | \
sed -e 's/<[^>]*>//g' | \
sed 's/^ *//' | \
cat -s | \
sed '/./,$!d' | \
cat > "$newName"
# Preserve timestamp from Evernote
timestamp=`get_timestamp "$1"`
touch -t $timestamp "$newName"
}
mkdir markdown
#convert_evernote_html_to_markdown "Being productive on the commute.html"
for filename in *.html; do
convert_evernote_html_to_markdown "$filename"
done
rm markdown/index.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment