Skip to content

Instantly share code, notes, and snippets.

@mayo
Created March 11, 2015 07:19
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mayo/6d4ef8397948f77ffdea to your computer and use it in GitHub Desktop.
Save mayo/6d4ef8397948f77ffdea to your computer and use it in GitHub Desktop.
Convert Simplenote Export JSON file into multiple Markdown files

SimpleNote to Markdown

This script converts JSON file from Simplenote Export web service into individual Markdown files.

It's nothing fancy, first argument is the JSON file, second argument is directory to write the notes to. The note files are named by using the first 60 characters (or a little more, up to a full word) of the first line of the note, stripped of any characters outside of letters, simple dash, underscore, brackets, space, single quote, and plug and equal signs.

Tags are stored on the bottom of the note on a line starting with "TAGS:", and the SimpleNote note ID/key as a "KEY:" line.

var fs = require('fs');
var source = process.argv[2];
var destDir = process.argv[3];
var notes = require("./" + source);
notes.forEach(function(note) {
var content = note.content.trim();
var filename = null;
var created = note.createdate;
var modified = note.modifydate;
var title = content.match(/(.*)\n+/)[1];
if (title) {
content = "# " + title.trim() + "\n\n" + content.substr(title.length).trim();
filename = title.trim();
} else {
console.log(note);
console.log(data);
throw new Error("can't figure out note");
}
//sanitize filename
filename = filename.replace(/([^\w-_\(\) '+=])/g, '');
//keep filename length sane
if (filename.length > 60) {
var sentencePos = filename.indexOf(".");
if (sentencePos > 0) filename = filename.substr(0, sentencePos);
if (filename.length > 60) {
spacePos = filename.indexOf(" ", 60);
if (spacePos > 0) filename = filename.substr(0, filename.indexOf(" ", 60));
}
}
//append .note to filename
filename += ".md"
if (note.tags || note.key) {
content += "\n\n";
if (note.tags) content += "TAGS: " + note.tags.join(", ") + "\n";
if (note.key) content += "KEY: " + note.key + "\n";
}
fs.writeFileSync(destDir + "/" + filename, content);
});
@draco-malfoy
Copy link

Even after 6 years, the ability to export/import as JSON/md is only available on windows and mac, android still doesn't support this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment