# HG changeset patch # User Paul Boddie # Date 1335214508 -7200 # Node ID fbaea6e06dffada3c7093e22d962ec1250468b68 # Parent 9105c385ca547058938f0a06c1b8319a0fe53b8c Added an exception for certain section types to avoid translating their content. Added a test of potentially problematic macros. diff -r 9105c385ca54 -r fbaea6e06dff parser.py --- a/parser.py Mon Apr 23 19:35:29 2012 +0200 +++ b/parser.py Mon Apr 23 22:55:08 2012 +0200 @@ -254,9 +254,13 @@ return rows -def translate_content(text): +def translate_content(text, sectiontype=None): - "Return a translation of the given 'text'." + """ + Return a translation of the given 'text'. If the optional 'sectiontype' is + specified, the translation may be modified to a form appropriate to the + section being translated. + """ parts = [] @@ -264,7 +268,14 @@ for match in content_regexp.finditer(text): start, end = match.span() parts.append(text[last:start]) - parts.append(translate_content_match(match)) + + # Handle unformatted sections. + + if sectiontype in ("code", "noformat"): + parts.append(match.group()) + else: + parts.append(translate_content_match(match)) + last = end parts.append(text[last:]) @@ -378,7 +389,7 @@ print >>out, "##", options else: print >>out, "{{{", - print >>out, translate_content(text), + print >>out, translate_content(text, sectiontype), print >>out, "}}}" print >>out diff -r 9105c385ca54 -r fbaea6e06dff tests/test_sections.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_sections.txt Mon Apr 23 22:55:08 2012 +0200 @@ -0,0 +1,15 @@ +{quote} +This is quoted content. +{quote} + +Later on, we might provide a list of child pages: + +{children} + +Sadly, whether these markers define sections or not depends on the content, not +general syntactic features. So, if we list the child pages again... + +{children} + +...we don't want the last paragraph to be in a special section, but then we have +to know that the "children" macro does not define a section.