# HG changeset patch # User Paul Boddie # Date 1543161435 -3600 # Node ID 032af926246bf75fcd480ec5aab2c77331409259 # Parent e7d30103073793c78623de7f08c4c4f9c2236723 Prevent some inline formatting markup from matching without closing markup occuring within the same paragraph. diff -r e7d301030737 -r 032af926246b moinformat/parsers/common.py --- a/moinformat/parsers/common.py Sat Nov 24 18:10:14 2018 +0100 +++ b/moinformat/parsers/common.py Sun Nov 25 16:57:15 2018 +0100 @@ -26,8 +26,9 @@ # Pattern management. ws_excl_nl = r"[ \f\r\t\v]" -quotes = "['" '"]' # ['"] -dotall = r"(.|\n)" +quotes = "['" '"]' # ['"] +dotall = r"(.|\n)" # behave similarly to dot with DOTALL option +dotparagraph = r"(.|\n(?!\r?\n))" # match everything within paragraphs def choice(l): @@ -91,6 +92,7 @@ value = value.replace(r"\N", ws_excl_nl) value = value.replace(r"\Q", quotes) value = value.replace(r"\E", dotall) + value = value.replace(r"\P", dotparagraph) patterns[name] = get_pattern(value) return patterns diff -r e7d301030737 -r 032af926246b moinformat/parsers/moin.py --- a/moinformat/parsers/moin.py Sat Nov 24 18:10:14 2018 +0100 +++ b/moinformat/parsers/moin.py Sun Nov 25 16:57:15 2018 +0100 @@ -508,6 +508,9 @@ def inline_patterns_for(self, name): + + "Return active patterns for the inline element having the given 'name'." + names = self.inline_pattern_names[:] names[names.index(name)] = "%send" % name return names @@ -721,14 +724,34 @@ # features. "fontstyle" : group("style", repeat("'", 2, 6)), # ''... - "larger" : r"~\+", # ~+ - "monospace" : r"`", # ` + + # Trivial markup balancing is done below using the end features. + + "larger" : join((r"~\+", # ~+ + expect(r"\P*?\+~"))), # ... +~ + + "monospace" : join((r"`", # ` + expect(r"\P*?`"))), # ... ` + + "smaller" : join((r"~-", # ~- + expect(r"\P*?-~"))), # ... -~ + + "strike" : join((r"--\(", # --( + expect(r"\P*?\)--"))), # ... )-- + + "sub" : join((r",,", # ,, + expect(r"\P*?,,"))), # ... ,, + + "super" : join((r"\^", # ^ + expect(r"\P*?\^"))), # ... ^ + + "underline" : join((r"__", # __ + expect(r"\P*?__"))), # ... __ + + # Rules are treated as inline but, unlike the above, appear without + # contents. + "rule" : group("rule", "-----*"), # ----... - "smaller" : r"~-", # ~- - "strike" : r"--\(", # --( - "sub" : r",,", # ,, - "super" : r"\^", # ^ - "underline" : r"__", # __ # Links and transclusions may start inline spans. diff -r e7d301030737 -r 032af926246b tests/test_formatting.tree --- a/tests/test_formatting.tree Sat Nov 24 18:10:14 2018 +0100 +++ b/tests/test_formatting.tree Sun Nov 25 16:57:15 2018 +0100 @@ -96,3 +96,12 @@ Text Verbatim Text + Break + Block + Text + Superscript + Text + Text + Break + Block + Text diff -r e7d301030737 -r 032af926246b tests/test_formatting.txt --- a/tests/test_formatting.txt Sat Nov 24 18:10:14 2018 +0100 +++ b/tests/test_formatting.txt Sun Nov 25 16:57:15 2018 +0100 @@ -17,3 +17,8 @@ Some --(deleted)-- text. Some <<>>. + +Some ^superscript text +wrapped^. + +Some ^not superscript text.