Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.