1.1 --- a/wikiparser.py Sat Jun 08 18:24:21 2013 +0200
1.2 +++ b/wikiparser.py Sat Jun 08 18:44:37 2013 +0200
1.3 @@ -309,6 +309,7 @@
1.4 def __init__(self):
1.5 self.max_level = self.level = 0
1.6 self.in_heading = False
1.7 + self.held_anchors = []
1.8
1.9 def translate_marker(self, marker):
1.10
1.11 @@ -404,13 +405,16 @@
1.12
1.13 elif match.group("macro"):
1.14 macro_name = match.group("macro")
1.15 - if macrotypes.has_key(macro_name) and not self.forbids_macros():
1.16 + if macrotypes.has_key(macro_name):
1.17 argname = macroargs.get(macro_name)
1.18 - return macrotypes[macro_name] % {
1.19 + result = macrotypes[macro_name] % {
1.20 "args" : quote_macro_argument((argname and ("%s=" % argname) or "") + match.group("options"))
1.21 }
1.22 - else:
1.23 - return ""
1.24 + if not self.forbids_macros():
1.25 + return result
1.26 + if macro_name == "anchor":
1.27 + self.held_anchors.append(result)
1.28 + return ""
1.29
1.30 elif match.group("italictext"):
1.31 return "''%s''" % self.translate_content(match.group("italictext"))
1.32 @@ -472,13 +476,17 @@
1.33
1.34 if blocktype in headings:
1.35 self.in_heading = True
1.36 + self.held_anchors = []
1.37
1.38 parts = []
1.39
1.40 # Translate headings and blockquotes.
1.41
1.42 if blocktypes.has_key(blocktype):
1.43 - parts.append(blocktypes[blocktype] % self.translate_content(blocktext))
1.44 + text = self.translate_content(blocktext)
1.45 + for anchor in self.held_anchors:
1.46 + parts.append(anchor)
1.47 + parts.append(blocktypes[blocktype] % text)
1.48
1.49 # Translate list items.
1.50