Last active
March 26, 2017 05:40
-
-
Save potatowire/e5e6e201ba61d565a74b469501d284b6 to your computer and use it in GitHub Desktop.
In iOS Copied App, formats excerpt from Kindle app as markdown blockquote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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