# HG changeset patch # User Paul Boddie # Date 1497625626 -7200 # Node ID 06641676740fac54d8b4ad4c22f5b0b0df780271 # Parent e565cc05d5d22be1d98b8dc37c96b148369d1820 Attempt to add Confluence 6 support with modified export and document formats. diff -r e565cc05d5d2 -r 06641676740f convert.py --- a/convert.py Fri Jun 16 17:06:10 2017 +0200 +++ b/convert.py Fri Jun 16 17:07:06 2017 +0200 @@ -3,7 +3,7 @@ """ Confluence XML dump conversion to a MoinMoin-compatible representation. -Copyright (C) 2012, 2013 Paul Boddie +Copyright (C) 2012, 2013, 2017 Paul Boddie This software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -130,7 +130,7 @@ content["version"], versionfile, title, # comment titles will incorporate the comment's position - content["lastModifierName"], + content.get("lastModifierName") or content.get("lastModifier"), content["versionComment"], date_to_seconds(content["lastModificationDate"]) )) @@ -185,8 +185,8 @@ # Handle attachments. elif objecttype == "Attachment": - pageid = content["content"] - version = content["attachmentVersion"] + pageid = content.get("content") or content.get("containerContent") + version = content.get("attachmentVersion") or content.get("version") or 0 if content.has_key("originalVersion"): attachid = content["originalVersion"] @@ -199,10 +199,10 @@ # Have to "taint" archive filenames, although Moin will # probably handle package script filename tainting. wikiutil.taintfilename(join("attachments", pageid, attachid, version)), - wikiutil.taintfilename(content["fileName"]), + wikiutil.taintfilename(content.get("fileName") or content.get("title")), "", # pagename is substituted later - content["lastModifierName"], - content["comment"], + content.get("lastModifierName") or content.get("lastModifier"), + content.get("comment") or content.get("versionComment"), date_to_seconds(content["lastModificationDate"]) )) diff -r e565cc05d5d2 -r 06641676740f xmlparser.py --- a/xmlparser.py Fri Jun 16 17:06:10 2017 +0200 +++ b/xmlparser.py Fri Jun 16 17:07:06 2017 +0200 @@ -3,7 +3,7 @@ """ Confluence Wiki XML/XHTML syntax parsing. -Copyright (C) 2012, 2013, 2015 Paul Boddie +Copyright (C) 2012, 2013, 2015, 2017 Paul Boddie This software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -206,7 +206,7 @@ # Remember macro information for use within the element. - if name == "ac:macro": + if name in ("ac:macro", "ac:structured-macro"): self.macros.append(self.attributes[-1].get("ac:name")) self.macro_parameters.append({}) @@ -233,7 +233,7 @@ # Discard macro state. - if name == "ac:macro": + if name in ("ac:macro", "ac:structured-macro"): self.macros.pop() self.macro_parameters.pop() @@ -401,8 +401,11 @@ # Some macros affect the formatting of their contents, whereas other # simpler macros are handled here. - elif name == "ac:macro": + elif name in ("ac:macro", "ac:structured-macro"): conversion = macrotypes.get(self.macros[-1]) + + # Produce the converted macro. + if conversion: parameters = {"content" : text} parameters.update(self.macro_parameters[-1]) @@ -410,11 +413,21 @@ if argnames: confargname, moinargname = argnames parameters["args"] = quote_macro_argument("%s=%s" % (moinargname, self.macro_parameters[-1][confargname])) + + # Obtain the Moin macro with parameters substituted. + text = conversion % parameters if self.macros[-1] == "anchor" and self.forbids_macros(): self.held_anchors.append(text) text = "" + # Warn about macros that are not converted. + + elif not macro_rich_text_styles.has_key(self.macros[-1]): + print >>sys.stderr, "No conversion possible for macro", self.macros[-1] + print >>sys.stderr, "Macro has arguments", self.macro_parameters[-1] + print >>sys.stderr + # Handle the common cases for parameterised and unparameterised # substitutions.