Skip to content

Instantly share code, notes, and snippets.

@kujenga
Last active September 3, 2019 23:43
Show Gist options
  • Save kujenga/092ec7ca11dd27dcd1ddcbfd28840b50 to your computer and use it in GitHub Desktop.
Save kujenga/092ec7ca11dd27dcd1ddcbfd28840b50 to your computer and use it in GitHub Desktop.
Utility to convert the Standard Notes conversion of Evernote data from HTML to Markdown
#!/usr/bin/env python3
#
# This script augments the converter tool provided by standard notes to provide
# Markdown instead of HTML as the format for the export, which is useful in
# particular after a conversion from Evernote exports [1]. This allows them to
# be viewed with other editors within the standard notes platform.
#
# The pandoc command like tool must be installed locally in order for this
# script to work.
#
# [1] https://dashboard.standardnotes.org/tools
import argparse
import subprocess
import json
def main(args):
with open(args.filename) as f:
raw = f.read()
data = json.loads(raw)
for item in data['items']:
if item['content_type'] != 'Note':
continue
html = item['content']['text']
item['content']['text'] = subprocess.run(
['pandoc', '--from=html', '--to=markdown_strict'],
input=html.encode('utf-8'), stdout=subprocess.PIPE,
).stdout.decode('utf-8')
print(json.dumps(data, indent=2))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('filename', default='evernote-to-sn.txt', nargs='?')
args = parser.parse_args()
main(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment