Skip to content

Instantly share code, notes, and snippets.

@rubys
Created November 7, 2014 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubys/dd96d4b2b834da1ad3b2 to your computer and use it in GitHub Desktop.
Save rubys/dd96d4b2b834da1ad3b2 to your computer and use it in GitHub Desktop.
Add macro support to transformAnchors
# expand anchor 'macros'
for anchor in anchors[:]:
if 'url#' in anchor:
anchors.remove(anchor)
urlprefix = anchor['url#']
del anchor['url#']
linkingText = anchor.get('linkingText')
if isinstance(linkingText, list):
for link in linkingText:
anchor['linkingText'] = link
anchor['url'] = urlprefix + simplifyText(link)
anchors.append(anchor.copy())
elif isinstance(linkingText, dict):
for text, link in linkingText.iteritems():
anchor['linkingText'] = text
anchor['url'] = urlprefix + link
anchors.append(anchor.copy())
elif isinstance(linkingText, basestring):
anchor['linkingText'] = linkingText
anchor['url'] = urlprefix + simplifyText(linkingText)
anchors.append(anchor.copy())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment