Skip to content

Instantly share code, notes, and snippets.

@dasevilla
Last active June 25, 2020 20:30
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dasevilla/d8421a13906c5ec937fc to your computer and use it in GitHub Desktop.
Save dasevilla/d8421a13906c5ec937fc to your computer and use it in GitHub Desktop.
Evernote to Markdown

Sample:

osascript export-selected.scpt \
    | saxon -xsl:enml2xhtml.xslt -s:- \
    | pandoc -f html -t markdown_strict \
    > output.md

open -a marked output.md

Install the dependies:

$ brew install haskell-platform saxon
$ cabal update
$ cabal install pandoc
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:en="http://xml.evernote.com/pub/enml2.dtd">
<!-- The goal of this stylesheet is to generate XHTML from ENML -->
<xsl:output method="xhtml" indent="yes"
xpath-default-namespace="http://www.w3.org/1999/xhtml"
doctype-system="http://www.w3.org/TR/html4/strict.dtd"
doctype-public="-//W3C//DTD HTML 4.01//EN" />
<!-- Handle en-note -->
<xsl:template match="en:en-note">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Exported note</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<!-- Handle en-todo -->
<xsl:template match="en:en-todo[@checked=true()]">
<xsl:text>[X] </xsl:text>
</xsl:template>
<xsl:template match="en:en-todo[@checked=false()]">
<xsl:text>[ ] </xsl:text>
</xsl:template>
<!-- Handle en-crypt -->
<!-- Handle en-media -->
<!-- Output unknown tags without modification -->
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*|text()|comment()|processing-instruction()">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
-- Export ENML from the first selected note
tell application "Evernote"
set theNotes to selection
if length of theNotes > 0 then
set theNote to first item of theNotes
set theContent to ENML content of theNote
set the clipboard to theContent
end if
end tell
return theContent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment