Fix bug #358: Non-breaking space removed from fixed-width literal.
[docutils.git] / docutils / test / test_writers / test_html4css1_parts.py
blob3f02b5e0e48caa7b191861df76117efb897800a9
1 #! /usr/bin/env python
3 # $Id$
4 # Author: reggie dugard <reggie@users.sourceforge.net>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Test for fragment code in HTML writer.
10 Note: the 'body' and 'whole' entries have been removed from the parts
11 dictionaries (redundant), along with 'meta' and 'stylesheet' entries with
12 standard values, and any entries with empty values.
13 """
15 from __init__ import DocutilsTestSupport
16 from docutils import core
18 def suite():
19 s = DocutilsTestSupport.HtmlPublishPartsTestSuite()
20 s.generateTests(totest)
21 return s
24 totest = {}
26 totest['Title promotion'] = ({'stylesheet_path': '',
27 'embed_stylesheet': 0}, [
28 ["""\
29 Simple String
30 """,
31 """\
32 {'fragment': '''<p>Simple String</p>\\n''',
33 'html_body': '''<div class="document">
34 <p>Simple String</p>
35 </div>\\n''',
36 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
37 """],
38 ["""\
39 Simple String with *markup*
40 """,
41 """\
42 {'fragment': '''<p>Simple String with <em>markup</em></p>\\n''',
43 'html_body': '''<div class="document">
44 <p>Simple String with <em>markup</em></p>
45 </div>\\n''',
46 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
47 """],
48 ["""\
49 Simple String with an even simpler ``inline literal``
50 """,
51 """\
52 {'fragment': '''<p>Simple String with an even simpler <tt class="docutils literal">inline literal</tt></p>\\n''',
53 'html_body': '''<div class="document">
54 <p>Simple String with an even simpler <tt class="docutils literal">inline literal</tt></p>
55 </div>\\n''',
56 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
57 """],
58 ["""\
59 Simple ``inline\xA0literal`` with NBSP
60 """,
61 """\
62 {'fragment': '''<p>Simple <tt class="docutils literal">inline&nbsp;literal</tt> with NBSP</p>\\n''',
63 'html_body': '''<div class="document">
64 <p>Simple <tt class="docutils literal">inline&nbsp;literal</tt> with NBSP</p>
65 </div>\\n''',
66 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
67 """],
68 ["""\
69 A simple `anonymous reference`__
71 __ http://www.test.com/test_url
72 """,
73 """\
74 {'fragment': '''<p>A simple <a class="reference external" href="http://www.test.com/test_url">anonymous reference</a></p>\\n''',
75 'html_body': '''<div class="document">
76 <p>A simple <a class="reference external" href="http://www.test.com/test_url">anonymous reference</a></p>
77 </div>\\n''',
78 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
79 """],
80 ["""\
81 One paragraph.
83 Two paragraphs.
84 """,
85 """\
86 {'fragment': '''<p>One paragraph.</p>
87 <p>Two paragraphs.</p>\\n''',
88 'html_body': '''<div class="document">
89 <p>One paragraph.</p>
90 <p>Two paragraphs.</p>
91 </div>\\n''',
92 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
93 """],
94 ["""\
95 A simple `named reference`_ with stuff in between the
96 reference and the target.
98 .. _`named reference`: http://www.test.com/test_url
99 """,
100 """\
101 {'fragment': '''<p>A simple <a class="reference external" href="http://www.test.com/test_url">named reference</a> with stuff in between the
102 reference and the target.</p>\\n''',
103 'html_body': '''<div class="document">
104 <p>A simple <a class="reference external" href="http://www.test.com/test_url">named reference</a> with stuff in between the
105 reference and the target.</p>
106 </div>\\n''',
107 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
108 """],
109 ["""\
110 +++++
111 Title
112 +++++
114 Subtitle
115 ========
117 Some stuff
119 Section
120 -------
122 Some more stuff
124 Another Section
125 ...............
127 And even more stuff
128 """,
129 """\
130 {'fragment': '''<p>Some stuff</p>
131 <div class="section" id="section">
132 <h1>Section</h1>
133 <p>Some more stuff</p>
134 <div class="section" id="another-section">
135 <h2>Another Section</h2>
136 <p>And even more stuff</p>
137 </div>
138 </div>\\n''',
139 'html_body': '''<div class="document" id="title">
140 <h1 class="title">Title</h1>
141 <h2 class="subtitle" id="subtitle">Subtitle</h2>
142 <p>Some stuff</p>
143 <div class="section" id="section">
144 <h1>Section</h1>
145 <p>Some more stuff</p>
146 <div class="section" id="another-section">
147 <h2>Another Section</h2>
148 <p>And even more stuff</p>
149 </div>
150 </div>
151 </div>\\n''',
152 'html_head': '''...<title>Title</title>\\n''',
153 'html_subtitle': '''<h2 class="subtitle" id="subtitle">Subtitle</h2>\\n''',
154 'html_title': '''<h1 class="title">Title</h1>\\n''',
155 'subtitle': '''Subtitle''',
156 'title': '''Title'''}
157 """],
158 ["""\
159 +++++
160 Title
161 +++++
163 :author: me
165 Some stuff
166 """,
167 """\
168 {'docinfo': '''<table class="docinfo" frame="void" rules="none">
169 <col class="docinfo-name" />
170 <col class="docinfo-content" />
171 <tbody valign="top">
172 <tr><th class="docinfo-name">Author:</th>
173 <td>me</td></tr>
174 </tbody>
175 </table>\\n''',
176 'fragment': '''<p>Some stuff</p>\\n''',
177 'html_body': '''<div class="document" id="title">
178 <h1 class="title">Title</h1>
179 <table class="docinfo" frame="void" rules="none">
180 <col class="docinfo-name" />
181 <col class="docinfo-content" />
182 <tbody valign="top">
183 <tr><th class="docinfo-name">Author:</th>
184 <td>me</td></tr>
185 </tbody>
186 </table>
187 <p>Some stuff</p>
188 </div>\\n''',
189 'html_head': '''...<title>Title</title>
190 <meta name="author" content="me" />\\n''',
191 'html_title': '''<h1 class="title">Title</h1>\\n''',
192 'meta': '''<meta name="author" content="me" />\\n''',
193 'title': '''Title'''}
194 """]
197 totest['No title promotion'] = ({'doctitle_xform' : 0,
198 'stylesheet_path': '',
199 'embed_stylesheet': 0}, [
200 ["""\
201 Simple String
202 """,
203 """\
204 {'fragment': '''<p>Simple String</p>\\n''',
205 'html_body': '''<div class="document">
206 <p>Simple String</p>
207 </div>\\n''',
208 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
209 """],
210 ["""\
211 Simple String with *markup*
212 """,
213 """\
214 {'fragment': '''<p>Simple String with <em>markup</em></p>\\n''',
215 'html_body': '''<div class="document">
216 <p>Simple String with <em>markup</em></p>
217 </div>\\n''',
218 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
219 """],
220 ["""\
221 Simple String with an even simpler ``inline literal``
222 """,
223 """\
224 {'fragment': '''<p>Simple String with an even simpler <tt class="docutils literal">inline literal</tt></p>\\n''',
225 'html_body': '''<div class="document">
226 <p>Simple String with an even simpler <tt class="docutils literal">inline literal</tt></p>
227 </div>\\n''',
228 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
229 """],
230 ["""\
231 A simple `anonymous reference`__
233 __ http://www.test.com/test_url
234 """,
235 """\
236 {'fragment': '''<p>A simple <a class="reference external" href="http://www.test.com/test_url">anonymous reference</a></p>\\n''',
237 'html_body': '''<div class="document">
238 <p>A simple <a class="reference external" href="http://www.test.com/test_url">anonymous reference</a></p>
239 </div>\\n''',
240 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
241 """],
242 ["""\
243 A simple `named reference`_ with stuff in between the
244 reference and the target.
246 .. _`named reference`: http://www.test.com/test_url
247 """,
248 """\
249 {'fragment': '''<p>A simple <a class="reference external" href="http://www.test.com/test_url">named reference</a> with stuff in between the
250 reference and the target.</p>\\n''',
251 'html_body': '''<div class="document">
252 <p>A simple <a class="reference external" href="http://www.test.com/test_url">named reference</a> with stuff in between the
253 reference and the target.</p>
254 </div>\\n''',
255 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
256 """],
257 ["""\
258 +++++
259 Title
260 +++++
262 Not A Subtitle
263 ==============
265 Some stuff
267 Section
268 -------
270 Some more stuff
272 Another Section
273 ...............
275 And even more stuff
276 """,
277 """\
278 {'fragment': '''<div class="section" id="title">
279 <h1>Title</h1>
280 <div class="section" id="not-a-subtitle">
281 <h2>Not A Subtitle</h2>
282 <p>Some stuff</p>
283 <div class="section" id="section">
284 <h3>Section</h3>
285 <p>Some more stuff</p>
286 <div class="section" id="another-section">
287 <h4>Another Section</h4>
288 <p>And even more stuff</p>
289 </div>
290 </div>
291 </div>
292 </div>\\n''',
293 'html_body': '''<div class="document">
294 <div class="section" id="title">
295 <h1>Title</h1>
296 <div class="section" id="not-a-subtitle">
297 <h2>Not A Subtitle</h2>
298 <p>Some stuff</p>
299 <div class="section" id="section">
300 <h3>Section</h3>
301 <p>Some more stuff</p>
302 <div class="section" id="another-section">
303 <h4>Another Section</h4>
304 <p>And even more stuff</p>
305 </div>
306 </div>
307 </div>
308 </div>
309 </div>\\n''',
310 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
311 """],
312 ["""\
313 * bullet
314 * list
315 """,
316 """\
317 {'fragment': '''<ul class="simple">
318 <li>bullet</li>
319 <li>list</li>
320 </ul>\\n''',
321 'html_body': '''<div class="document">
322 <ul class="simple">
323 <li>bullet</li>
324 <li>list</li>
325 </ul>
326 </div>\\n''',
327 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
328 """],
329 ["""\
330 .. table::
331 :align: right
333 +-----+-----+
334 | 1 | 2 |
335 +-----+-----+
336 | 3 | 4 |
337 +-----+-----+
338 """,
339 """\
340 {'fragment': '''<table border="1" class="docutils align-right">
341 <colgroup>
342 <col width="50%%" />
343 <col width="50%%" />
344 </colgroup>
345 <tbody valign="top">
346 <tr><td>1</td>
347 <td>2</td>
348 </tr>
349 <tr><td>3</td>
350 <td>4</td>
351 </tr>
352 </tbody>
353 </table>\\n''',
354 'html_body': '''<div class="document">
355 <table border="1" class="docutils align-right">
356 <colgroup>
357 <col width="50%%" />
358 <col width="50%%" />
359 </colgroup>
360 <tbody valign="top">
361 <tr><td>1</td>
362 <td>2</td>
363 </tr>
364 <tr><td>3</td>
365 <td>4</td>
366 </tr>
367 </tbody>
368 </table>
369 </div>\\n''',
370 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
371 """],
372 ["""\
373 Not a docinfo.
375 :This: .. _target:
379 :simple:
380 :field: list
381 """,
382 """\
383 {'fragment': '''<p>Not a docinfo.</p>
384 <table class="docutils field-list" frame="void" rules="none">
385 <col class="field-name" />
386 <col class="field-body" />
387 <tbody valign="top">
388 <tr class="field"><th class="field-name">This:</th><td class="field-body"><p class="first last" id="target">is</p>
389 </td>
390 </tr>
391 <tr class="field"><th class="field-name">a:</th><td class="field-body"></td>
392 </tr>
393 <tr class="field"><th class="field-name">simple:</th><td class="field-body"></td>
394 </tr>
395 <tr class="field"><th class="field-name">field:</th><td class="field-body">list</td>
396 </tr>
397 </tbody>
398 </table>\\n''',
399 'html_body': '''<div class="document">
400 <p>Not a docinfo.</p>
401 <table class="docutils field-list" frame="void" rules="none">
402 <col class="field-name" />
403 <col class="field-body" />
404 <tbody valign="top">
405 <tr class="field"><th class="field-name">This:</th><td class="field-body"><p class="first last" id="target">is</p>
406 </td>
407 </tr>
408 <tr class="field"><th class="field-name">a:</th><td class="field-body"></td>
409 </tr>
410 <tr class="field"><th class="field-name">simple:</th><td class="field-body"></td>
411 </tr>
412 <tr class="field"><th class="field-name">field:</th><td class="field-body">list</td>
413 </tr>
414 </tbody>
415 </table>
416 </div>\\n''',
417 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
418 """],
419 ["""\
420 Not a docinfo.
422 :This is: a
423 :simple field list with loooong field: names
424 """,
425 """\
426 {'fragment': '''<p>Not a docinfo.</p>
427 <table class="docutils field-list" frame="void" rules="none">
428 <col class="field-name" />
429 <col class="field-body" />
430 <tbody valign="top">
431 <tr class="field"><th class="field-name">This is:</th><td class="field-body">a</td>
432 </tr>
433 <tr class="field"><th class="field-name" colspan="2">simple field list with loooong field:</th></tr>
434 <tr class="field"><td>&nbsp;</td><td class="field-body">names</td>
435 </tr>
436 </tbody>
437 </table>\\n''',
438 'html_body': '''<div class="document">
439 <p>Not a docinfo.</p>
440 <table class="docutils field-list" frame="void" rules="none">
441 <col class="field-name" />
442 <col class="field-body" />
443 <tbody valign="top">
444 <tr class="field"><th class="field-name">This is:</th><td class="field-body">a</td>
445 </tr>
446 <tr class="field"><th class="field-name" colspan="2">simple field list with loooong field:</th></tr>
447 <tr class="field"><td>&nbsp;</td><td class="field-body">names</td>
448 </tr>
449 </tbody>
450 </table>
451 </div>\\n''',
452 'html_head': '''...<title>&lt;string&gt;</title>\\n'''}
453 """],
457 if __name__ == '__main__':
458 import unittest
459 unittest.main(defaultTest='suite')