2017-04-26 | Paul Boddie | file changeset files shortlog | Introduced notions of transparent regions that should be parsed as wiki text, first normalising the text nodes in parsed regions before expanding the nodes in transparent regions by applying region text parsing rules. Simplified the test code and added testing of transparent regions. |
paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | from moinformat import parse, serialise, HTMLSerialiser |
paul@0 | 4 | |
paul@1 | 5 | s0 = """\ |
paul@1 | 6 | Hello |
paul@1 | 7 | {{{{#!wiki |
paul@1 | 8 | A region |
paul@1 | 9 | {{{ |
paul@1 | 10 | Another |
paul@1 | 11 | }}} |
paul@1 | 12 | End |
paul@1 | 13 | }}}} |
paul@1 | 14 | XXX |
paul@1 | 15 | """ |
paul@1 | 16 | |
paul@1 | 17 | s1 = """\ |
paul@0 | 18 | Hello |
paul@0 | 19 | {{{{#!xxx |
paul@0 | 20 | A region |
paul@0 | 21 | {{{ |
paul@0 | 22 | Another |
paul@0 | 23 | }}} |
paul@0 | 24 | End |
paul@0 | 25 | }}}} |
paul@0 | 26 | XXX |
paul@0 | 27 | """ |
paul@0 | 28 | |
paul@0 | 29 | s2 = """\ |
paul@0 | 30 | Hello |
paul@0 | 31 | {{{{ |
paul@0 | 32 | Start |
paul@0 | 33 | }}} |
paul@0 | 34 | Still in region |
paul@0 | 35 | }}}} |
paul@0 | 36 | End |
paul@0 | 37 | """ |
paul@0 | 38 | |
paul@0 | 39 | s3 = """\ |
paul@0 | 40 | Hello {{{world}}} again""" |
paul@0 | 41 | |
paul@1 | 42 | d0 = parse(s0) |
paul@1 | 43 | d1 = parse(s1) |
paul@0 | 44 | d2 = parse(s2) |
paul@0 | 45 | d3 = parse(s3) |
paul@0 | 46 | |
paul@1 | 47 | ns0 = serialise(d0) |
paul@1 | 48 | ns1 = serialise(d1) |
paul@0 | 49 | ns2 = serialise(d2) |
paul@0 | 50 | ns3 = serialise(d3) |
paul@0 | 51 | |
paul@1 | 52 | for s, n in zip([s0, s1, s2, s3], [ns0, ns1, ns2, ns3]): |
paul@1 | 53 | print n == s |
paul@1 | 54 | print |
paul@1 | 55 | print n |
paul@1 | 56 | print "----" |
paul@0 | 57 | |
paul@1 | 58 | for d in [d0, d1, d2, d3]: |
paul@1 | 59 | print serialise(d, HTMLSerialiser) |
paul@1 | 60 | print "----" |
paul@0 | 61 | |
paul@0 | 62 | # vim: tabstop=4 expandtab shiftwidth=4 |