ConfluenceConverter

Changeset

146:1d93ae7fe8ed
2017-06-16 Paul Boddie raw files shortlog changelog graph Introduced support for multiple macro arguments along with some new macros.
xmlparser.py (file)
     1.1 --- a/xmlparser.py	Fri Jun 16 19:05:37 2017 +0200
     1.2 +++ b/xmlparser.py	Fri Jun 16 19:06:27 2017 +0200
     1.3 @@ -82,7 +82,7 @@
     1.4  
     1.5  preformatted_tags = ["pre", "ac:plain-text-body"]
     1.6  single_level_tags = ["strong", "em", "u", "del", "sup", "sub", "code"]
     1.7 -formatted_tags    = ["ac:rich-text-body", "table"]
     1.8 +formatted_tags    = ["ac:layout", "ac:rich-text-body", "table"]
     1.9  
    1.10  indented_tags = ["li", "p"] + preformatted_tags + formatted_tags
    1.11  block_tags = indented_tags + blocktypes.keys() + list_tags.keys()
    1.12 @@ -122,13 +122,16 @@
    1.13  
    1.14  macroargs = {
    1.15      # Confluence macro        Confluence and MoinMoin macro arguments
    1.16 -    "color"                 : ("color", "col"),
    1.17 +    "attachments"           : [("page", "pagename")],
    1.18 +    "color"                 : [("color", "col")],
    1.19      }
    1.20  
    1.21  macrotypes = {
    1.22      # Confluence macro        MoinMoin syntax
    1.23      "anchor"                : "<<Anchor(%(anchor)s)>>",
    1.24 +    "attachments"           : "<<AttachList(%(args)s)>>",
    1.25      "color"                 : "<<Color2(%(content)s, %(args)s)>>",
    1.26 +    "recently-updated"      : "<<RecentChanges>>",
    1.27      "toc"                   : "<<TableOfContents>>",
    1.28      }
    1.29  
    1.30 @@ -410,9 +413,17 @@
    1.31                  parameters = {"content" : text}
    1.32                  parameters.update(self.macro_parameters[-1])
    1.33                  argnames = macroargs.get(self.macros[-1])
    1.34 +
    1.35 +                # Convert Confluence arguments to Moin arguments. Unlike the
    1.36 +                # wiki markup parser, multiple arguments are supported.
    1.37 +
    1.38                  if argnames:
    1.39 -                    confargname, moinargname = argnames
    1.40 -                    parameters["args"] = quote_macro_argument("%s=%s" % (moinargname, self.macro_parameters[-1][confargname]))
    1.41 +                    all_args = []
    1.42 +                    for confargname, moinargname in argnames:
    1.43 +                        argvalue = self.macro_parameters[-1].get(confargname)
    1.44 +                        if argvalue:
    1.45 +                            all_args.append(quote_macro_argument("%s=%s" % (moinargname, argvalue)))
    1.46 +                    parameters["args"] = ", ".join(all_args)
    1.47  
    1.48                  # Obtain the Moin macro with parameters substituted.
    1.49