Skip to content

Instantly share code, notes, and snippets.

@Donohue
Last active September 6, 2016 12:00
Show Gist options
  • Save Donohue/46b8f719f4d37f379f9f to your computer and use it in GitHub Desktop.
Save Donohue/46b8f719f4d37f379f9f to your computer and use it in GitHub Desktop.
def fragmention(self, bookmark):
# Normalize whitespace and encode text as UTF8
text = ' '.join(self.text.split()).encode('utf-8')
url_parts = urlparse(bookmark.url)
# If the URL has no path (i.e. http://google.com) add a "/" then append fragmention
formatter = '%s/##%s' if not len(url_parts.path) else '%s##%s'
fragmention_url = formatter % (url_parts.geturl(), urllib.quote_plus(text))
# Ensure we highlight the correct instance of the referenced text
if self.position > 0:
fragmention_url += '++%d' % self.position
return fragmention_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment