# HG changeset patch # User Paul Boddie # Date 1370863227 -7200 # Node ID 589001c9539edb37d32f29c16c708a160735f3eb # Parent ba33e8011a6f67d072af6dc6635c7759ffcb5f57 Removed interpretation of the "link-body" attribute as a possible link anchor. Added a common function for producing page titles. diff -r ba33e8011a6f -r 589001c9539e common.py --- a/common.py Mon Jun 10 01:54:44 2013 +0200 +++ b/common.py Mon Jun 10 13:20:27 2013 +0200 @@ -21,6 +21,8 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ +MAX_TITLE_LENGTH = 120 + URL_SCHEMES = ("http", "https", "ftp", "mailto") # Translation helpers. @@ -37,6 +39,9 @@ headings = blocktypes.keys(); headings.remove("bq") +def get_page_title(title): + return title[:MAX_TITLE_LENGTH].strip() + def quote_macro_argument(arg): if arg.find('"') != -1: return '"%s"' % arg.replace('"', '""') diff -r ba33e8011a6f -r 589001c9539e convert.py --- a/convert.py Mon Jun 10 01:54:44 2013 +0200 +++ b/convert.py Mon Jun 10 13:20:27 2013 +0200 @@ -31,7 +31,7 @@ import wikiparser, xmlparser import sys -MAX_TITLE_LENGTH = 120 +from common import get_page_title class ConfluenceHandler: @@ -109,7 +109,7 @@ # Limit the title to a "safe" number of characters in order to avoid # filesystem issues. - title = title[:MAX_TITLE_LENGTH].strip() + title = get_page_title(title) if title: title = "%s/%s" % (self.space, title) diff -r ba33e8011a6f -r 589001c9539e xmlparser.py --- a/xmlparser.py Mon Jun 10 01:54:44 2013 +0200 +++ b/xmlparser.py Mon Jun 10 13:20:27 2013 +0200 @@ -56,8 +56,8 @@ "p" : "%s", "ol" : "%s", "ul" : "%s", - "ac:link" : "[[%s%s|%s]]", - "ac:image" : "{{%s%s|%s}}", + "ac:link" : "[[%s%s%s|%s]]", + "ac:image" : "{{%s%s%s|%s}}", "a" : "[[%s|%s]]", } @@ -109,7 +109,6 @@ # Confluence element MoinMoin link prefix "ri:attachment" : "attachment:", "ri:user" : "", - "ac:link-body" : "#", } macro_rich_text_styles = { @@ -299,8 +298,6 @@ # For anchor links, just use the raw text and let Moin do the formatting. elif name == "ac:link-body": - if not self.target_type: - self.target_type = name self.label = text.strip() text = "" @@ -371,8 +368,9 @@ if name in ("ac:link", "ac:image"): prefix = link_target_types.get(self.target_type, "") - anchor = self.attributes[-1].get("ac:anchor") - text = conversion % (prefix, anchor or self.target, self.label or text.strip() or self.target) + anchor = self.attributes[-1].get("ac:anchor") or "" + label = self.label or text.strip() or self.target + text = conversion % (prefix, self.target, anchor and ("#%s" % anchor) or "", label) self.target = self.target_type = self.label = None elif name == "a":