Skip to content

Instantly share code, notes, and snippets.

@potatowire
Last active March 26, 2017 05:40
Show Gist options
  • Save potatowire/e5e6e201ba61d565a74b469501d284b6 to your computer and use it in GitHub Desktop.
Save potatowire/e5e6e201ba61d565a74b469501d284b6 to your computer and use it in GitHub Desktop.
In iOS Copied App, formats excerpt from Kindle app as markdown blockquote
// A clipping object is a JavaScript object
// that contains the following properties.
// Properties values may be null.
// title (String)
// text (String)
// url (String)
// saveDate (Date)
// Return true if the clipping can be reformatted with this script.
function canFormat(clipping) {
return clipping.text != null
}
// Process data and return a new/updated clipping object or a string.
function format(clipping) {
// regex unique to the way Kindle app sends quotes
// allows internal "
var match = /"(.*?)" from/g.exec(clipping.text);
// strip enclosing " and make md blockquote
clipping.text = '> ' + match[0].replace(/^"{1}/g, '').replace(/" from$/g, '') + ' [Kindle link](' + clipping.url + ')\n> \n';
return clipping.text
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment