1.1 --- a/TO_DO.txt Sat Jan 10 15:11:34 2015 +0100
1.2 +++ b/TO_DO.txt Mon Feb 02 15:18:19 2015 +0100
1.3 @@ -1,3 +1,13 @@
1.4 +Recent Issues
1.5 +=============
1.6 +
1.7 +Linking in pages with slash characters in the actual titles. (Difficult to
1.8 +handle, especially if the pages eventually get renamed.)
1.9 +
1.10 +(Linking from comment subpages.)
1.11 +
1.12 +
1.13 +
1.14 Enhancements
1.15 ============
1.16
2.1 --- a/convert.py Sat Jan 10 15:11:34 2015 +0100
2.2 +++ b/convert.py Mon Feb 02 15:18:19 2015 +0100
2.3 @@ -164,17 +164,19 @@
2.4 if not body:
2.5 body = "## Empty page."
2.6
2.7 + is_comment_page = content.get("content:class") == "Comment"
2.8 +
2.9 # NOTE: Very simple technique employed for guessing the format.
2.10
2.11 if no_translate:
2.12 - fn = write
2.13 + fn = notranslate
2.14 elif body.startswith("<"):
2.15 fn = xmltranslate
2.16 else:
2.17 fn = translate
2.18
2.19 try:
2.20 - fn(join(versions_dir, content["content"]), body)
2.21 + fn(join(versions_dir, content["content"]), body, is_comment_page)
2.22 except:
2.23 err = codecs.getwriter("utf-8")(sys.stderr)
2.24 print >>err, "Error parsing", content["content"]
2.25 @@ -210,7 +212,12 @@
2.26
2.27 "Record properties in the current content dictionary."
2.28
2.29 - self.content[attributes[-1]["name"]] = text.strip()
2.30 + property_name = attributes[-1]["name"]
2.31 + self.content[property_name] = text.strip()
2.32 +
2.33 + property_class = attributes[-1].get("class")
2.34 + if property_class:
2.35 + self.content["%s:%s" % (property_name, "class")] = property_class.strip()
2.36
2.37 def handle_id(self, name, elements, attributes, all_text, text):
2.38
2.39 @@ -272,7 +279,7 @@
2.40 finally:
2.41 f.close()
2.42
2.43 -def translate(filename, body, fn=None):
2.44 +def translate(filename, body, is_comment_page, fn=None):
2.45
2.46 """
2.47 Write to the file with the given 'filename' a translation of the given
2.48 @@ -284,12 +291,15 @@
2.49 out = codecs.open(filename, "w", encoding="utf-8")
2.50 try:
2.51 print >>out, "#pragma page-filename", filename
2.52 - fn(body, out)
2.53 + fn(body, out, is_comment_page)
2.54 finally:
2.55 out.close()
2.56
2.57 -def xmltranslate(filename, body):
2.58 - translate(filename, body, xmlparser.parse)
2.59 +def xmltranslate(filename, body, is_comment_page):
2.60 + translate(filename, body, is_comment_page, xmlparser.parse)
2.61 +
2.62 +def notranslate(filename, body, is_comment_page):
2.63 + write(filename, body)
2.64
2.65 def sort_comments(pages_dir, pageid):
2.66
3.1 --- a/wikiparser.py Sat Jan 10 15:11:34 2015 +0100
3.2 +++ b/wikiparser.py Mon Feb 02 15:18:19 2015 +0100
3.3 @@ -3,7 +3,7 @@
3.4 """
3.5 Confluence Wiki syntax parsing.
3.6
3.7 -Copyright (C) 2012, 2013 Paul Boddie <paul@boddie.org.uk>
3.8 +Copyright (C) 2012, 2013, 2015 Paul Boddie <paul@boddie.org.uk>
3.9
3.10 This software is free software; you can redistribute it and/or
3.11 modify it under the terms of the GNU General Public License as
3.12 @@ -425,7 +425,8 @@
3.13
3.14 "A parser for Confluence markup."
3.15
3.16 - def __init__(self):
3.17 + def __init__(self, is_comment_page=False):
3.18 + self.is_comment_page = is_comment_page
3.19 self.max_level = self.level = 0
3.20 self.in_heading = False
3.21 self.held_anchors = []
3.22 @@ -495,6 +496,8 @@
3.23
3.24 else:
3.25 prefix = "../"
3.26 + if self.is_comment_page:
3.27 + prefix += "../"
3.28
3.29 # Make the link tidier by making a target if none was given.
3.30
3.31 @@ -804,11 +807,11 @@
3.32 def forbids_macros(self):
3.33 return self.in_heading or self.macro
3.34
3.35 -def parse(s, out):
3.36 +def parse(s, out, is_comment_page=False):
3.37
3.38 "Parse the content in the string 's', writing a translation to 'out'."
3.39
3.40 - parser = ConfluenceParser()
3.41 + parser = ConfluenceParser(is_comment_page)
3.42 out.write(parser.parse_text(s, top=True))
3.43
3.44 if __name__ == "__main__":
4.1 --- a/xmlparser.py Sat Jan 10 15:11:34 2015 +0100
4.2 +++ b/xmlparser.py Mon Feb 02 15:18:19 2015 +0100
4.3 @@ -139,9 +139,10 @@
4.4
4.5 "Handle content from Confluence 4 page revisions."
4.6
4.7 - def __init__(self, out):
4.8 + def __init__(self, out, is_comment_page=False):
4.9 Parser.__init__(self)
4.10 self.out = out
4.11 + self.is_comment_page = is_comment_page
4.12
4.13 # Link target and label information.
4.14
4.15 @@ -302,6 +303,8 @@
4.16 prefix = link_target_prefixes.get(attrname)
4.17 if prefix:
4.18 target_details.insert(0, prefix)
4.19 + if self.is_comment_page:
4.20 + target_details.insert(0, prefix)
4.21
4.22 # Make a link based on the details.
4.23
4.24 @@ -511,7 +514,7 @@
4.25 def normalise(self, text, name):
4.26 return normalise_regexp.sub(self.get_replacement(name), text)
4.27
4.28 -def parse(s, out):
4.29 +def parse(s, out, is_comment_page=False):
4.30
4.31 "Parse the content in the string 's', writing a translation to 'out'."
4.32
4.33 @@ -530,7 +533,7 @@
4.34
4.35 f = StringIO(s.encode("utf-8"))
4.36 try:
4.37 - parser = ConfluenceXMLParser(out)
4.38 + parser = ConfluenceXMLParser(out, is_comment_page)
4.39 parser.parse(f)
4.40 finally:
4.41 f.close()