comparison tests/test-minirst.py @ 9156:c9c7e8cdac9c

minimal reStructuredText parser
author Martin Geisler <mg@lazybytes.net>
date Thu, 16 Jul 2009 23:25:25 +0200
parents
children cd5b6a11b607
comparison
equal deleted inserted replaced
9155:b46063eabe98 9156:c9c7e8cdac9c
1 #!/usr/bin/env python
2
3 from mercurial import minirst
4
5 def debugformat(title, text, width):
6 print "%s formatted to fit within %d characters:" % (title, width)
7 print "-" * 70
8 print minirst.format(text, width)
9 print "-" * 70
10 print
11
12 paragraphs = """
13 This is some text in the first paragraph.
14
15 An indented paragraph
16 with just two lines.
17
18
19 The third paragraph. It is followed by some
20 random lines with spurious spaces.
21
22
23
24
25
26 No indention
27 here, despite
28 the uneven left
29 margin.
30
31 Only the
32 left-most line
33 (this line!)
34 is significant
35 for the indentation
36
37 """
38
39 debugformat('paragraphs', paragraphs, 60)
40 debugformat('paragraphs', paragraphs, 30)
41
42
43 definitions = """
44 A Term
45 Definition. The indented
46 lines make up the definition.
47 Another Term
48 Another definition. The final line in the
49 definition determines the indentation, so
50 this will be indented with four spaces.
51
52 A Nested/Indented Term
53 Definition.
54 """
55
56 debugformat('definitions', definitions, 60)
57 debugformat('definitions', definitions, 30)
58
59
60 literals = r"""
61 The fully minimized form is the most
62 convenient form::
63
64 Hello
65 literal
66 world
67
68 In the partially minimized form a paragraph
69 simply ends with space-double-colon. ::
70
71 ////////////////////////////////////////
72 long un-wrapped line in a literal block
73 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
74
75 ::
76
77 This literal block is started with '::',
78 the so-called expanded form. The paragraph
79 with '::' disappears in the final output.
80 """
81
82 debugformat('literals', literals, 60)
83 debugformat('literals', literals, 30)
84
85
86 lists = """
87 - This is the first list item.
88
89 Second paragraph in the first list item.
90
91 - List items need not be separated
92 by a blank line.
93 - And will be rendered without
94 one in any case.
95
96 We can have indented lists:
97
98 - This is an indented list item
99
100 - Another indented list item::
101
102 - A literal block in the middle
103 of an indented list.
104
105 (The above is not a list item since we are in the literal block.)
106
107 ::
108
109 Literal block with no indentation.
110 """
111
112 debugformat('lists', lists, 60)
113 debugformat('lists', lists, 30)
114
115
116 options = """
117 There is support for simple option lists,
118 but only with long options:
119
120 --all Output all.
121 --both Output both (this description is
122 quite long).
123 --long Output all day long.
124
125 --par This option has two paragraphs in its description.
126 This is the first.
127
128 This is the second. Blank lines may be omitted between
129 options (as above) or left in (as here).
130
131 The next paragraph looks like an option list, but lacks the two-space
132 marker after the option. It is treated as a normal paragraph:
133
134 --foo bar baz
135 """
136
137 debugformat('options', options, 60)
138 debugformat('options', options, 30)