Last active
September 6, 2016 12:00
-
-
Save Donohue/46b8f719f4d37f379f9f to your computer and use it in GitHub Desktop.
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
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