Created
November 7, 2014 16:51
-
-
Save rubys/dd96d4b2b834da1ad3b2 to your computer and use it in GitHub Desktop.
Add macro support to transformAnchors
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
# 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