Debian Codegraph @

test/test_parsers/test_rst/test_inline_markup.py

raw symbols SCIP
1 #! /usr/bin/env python3
2 # $Id: test_inline_markup.py 10308 2026-03-28 18:54:25Z milde $
3 # Author: David Goodger <[email protected]>
4 # Copyright: This module has been placed in the public domain.
5
6 """
7 Tests for inline markup in docutils/parsers/rst/states.py.
8 Interpreted text tests are in a separate module, test_interpreted.py.
9 """
10
11 from pathlib import Path
12 import sys
13 import unittest
14
15 if __name__ == '__main__':
16 # prepend the "docutils root" to the Python library path
17 # so we import the local `docutils` package.
18 sys.path.insert(0, str(Path(__file__).resolve().parents[3]))
19
20 from docutils.frontend import get_default_settings
21 from docutils.parsers.rst import Parser
22 from docutils.utils import new_document
23
24
25 class ParserTestCase(unittest.TestCase):
26 maxDiff = None
27
28 def test_parser(self):
29 parser = Parser()
30 settings = get_default_settings(Parser)
31 settings.warning_stream = ''
32 settings.legacy_ids = False
33 for name, cases in totest.items():
34 for casenum, (case_input, case_expected) in enumerate(cases):
35 with self.subTest(id=f'totest[{name!r}][{casenum}]'):
36 document = new_document('test data', settings.copy())
37 parser.parse(case_input, document)
38 output = document.pformat()
39 self.assertEqual(case_expected, output)
40
41
42 totest = {}
43
44 totest['emphasis'] = [
45 ["""\
46 *emphasis*
47 """,
48 """\
49 <document source="test data">
50 <paragraph>
51 <emphasis>
52 emphasis
53 """],
54 ["""\
55 l'*emphasis* with the *emphasis*' apostrophe.
56 l\u2019*emphasis* with the *emphasis*\u2019 apostrophe.
57 """,
58 """\
59 <document source="test data">
60 <paragraph>
61 l\'
62 <emphasis>
63 emphasis
64 with the \n\
65 <emphasis>
66 emphasis
67 \' apostrophe.
68 l\u2019
69 <emphasis>
70 emphasis
71 with the \n\
72 <emphasis>
73 emphasis
74 \u2019 apostrophe.
75 """],
76 ["""\
77 *emphasized sentence
78 across lines*
79 """,
80 """\
81 <document source="test data">
82 <paragraph>
83 <emphasis>
84 emphasized sentence
85 across lines
86 """],
87 ["""\
88 *emphasis without closing asterisk
89 """,
90 """\
91 <document source="test data">
92 <paragraph>
93 <problematic ids="problematic-1" refid="system-message-1">
94 *
95 emphasis without closing asterisk
96 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="1" source="test data" type="WARNING">
97 <paragraph>
98 Inline emphasis start-string without end-string.
99 """],
100 [r"""some punctuation is allowed around inline markup, e.g.
101 /*emphasis*/, -*emphasis*-, and :*emphasis*: (delimiters),
102 (*emphasis*), [*emphasis*], <*emphasis*>, {*emphasis*} (open/close pairs)
103 *emphasis*., *emphasis*,, *emphasis*!, and *emphasis*\ (closing delimiters),
104
105 but not
106 )*emphasis*(, ]*emphasis*[, >*emphasis*>, }*emphasis*{ (close/open pairs),
107 (*), [*], '*' or '"*"' ("quoted" start-string),
108 x*2* or 2*x* (alphanumeric char before),
109 \*args or * (escaped, whitespace behind start-string),
110 or *the\* *stars\* *inside* (escaped, whitespace before end-string).
111
112 However, '*args' will trigger a warning and may be problematic.
113
114 what about *this**?
115 """,
116 """\
117 <document source="test data">
118 <paragraph>
119 some punctuation is allowed around inline markup, e.g.
120 /
121 <emphasis>
122 emphasis
123 /, -
124 <emphasis>
125 emphasis
126 -, and :
127 <emphasis>
128 emphasis
129 : (delimiters),
130 (
131 <emphasis>
132 emphasis
133 ), [
134 <emphasis>
135 emphasis
136 ], <
137 <emphasis>
138 emphasis
139 >, {
140 <emphasis>
141 emphasis
142 } (open/close pairs)
143 <emphasis>
144 emphasis
145 ., \n\
146 <emphasis>
147 emphasis
148 ,, \n\
149 <emphasis>
150 emphasis
151 !, and \n\
152 <emphasis>
153 emphasis
154 (closing delimiters),
155 <paragraph>
156 but not
157 )*emphasis*(, ]*emphasis*[, >*emphasis*>, }*emphasis*{ (close/open pairs),
158 (*), [*], '*' or '"*"' ("quoted" start-string),
159 x*2* or 2*x* (alphanumeric char before),
160 *args or * (escaped, whitespace behind start-string),
161 or \n\
162 <emphasis>
163 the* *stars* *inside
164 (escaped, whitespace before end-string).
165 <paragraph>
166 However, '
167 <problematic ids="problematic-1" refid="system-message-1">
168 *
169 args' will trigger a warning and may be problematic.
170 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="13" source="test data" type="WARNING">
171 <paragraph>
172 Inline emphasis start-string without end-string.
173 <paragraph>
174 what about \n\
175 <emphasis>
176 this*
177 ?
178 """],
179 ["""\
180 Quotes around inline markup:
181
182 '*emphasis*' "*emphasis*" Straight,
183 ‘*emphasis*’ “*emphasis*” English, ...,
184 « *emphasis* » ‹ *emphasis* › « *emphasis* » ‹ *emphasis* ›
185 « *emphasis* » ‹ *emphasis* › French,
186 „*emphasis*“ ‚*emphasis*‘ »*emphasis*« ›*emphasis*‹ German, Czech, ...,
187 „*emphasis*” «*emphasis*» Romanian,
188 “*emphasis*„ ‘*emphasis*‚ Greek,
189 「*emphasis*」 『*emphasis*』traditional Chinese,
190 ”*emphasis*” ’*emphasis*’ »*emphasis*» ›*emphasis*› Swedish, Finnish,
191 „*emphasis*” ‚*emphasis*’ Polish,
192 „*emphasis*” »*emphasis*« ’*emphasis*’ Hungarian,
193 """,
194 """\
195 <document source="test data">
196 <paragraph>
197 Quotes around inline markup:
198 <paragraph>
199 \'
200 <emphasis>
201 emphasis
202 \' "
203 <emphasis>
204 emphasis
205 " Straight,
206 \u2018
207 <emphasis>
208 emphasis
209 \u2019 \u201c
210 <emphasis>
211 emphasis
212 \u201d English, ...,
213 \xab\u202f
214 <emphasis>
215 emphasis
216 \u202f\xbb \u2039\u202f
217 <emphasis>
218 emphasis
219 \u202f\u203a \xab\xa0
220 <emphasis>
221 emphasis
222 \xa0\xbb \u2039\xa0
223 <emphasis>
224 emphasis
225 \xa0\u203a
226 \xab\u2005
227 <emphasis>
228 emphasis
229 \u2005\xbb \u2039\u2005
230 <emphasis>
231 emphasis
232 \u2005\u203a French,
233 \u201e
234 <emphasis>
235 emphasis
236 \u201c \u201a
237 <emphasis>
238 emphasis
239 \u2018 \xbb
240 <emphasis>
241 emphasis
242 \xab \u203a
243 <emphasis>
244 emphasis
245 \u2039 German, Czech, ...,
246 \u201e
247 <emphasis>
248 emphasis
249 \u201d \xab
250 <emphasis>
251 emphasis
252 \xbb Romanian,
253 \u201c
254 <emphasis>
255 emphasis
256 \u201e \u2018
257 <emphasis>
258 emphasis
259 \u201a Greek,
260 \u300c
261 <emphasis>
262 emphasis
263 \u300d \u300e
264 <emphasis>
265 emphasis
266 \u300ftraditional Chinese,
267 \u201d
268 <emphasis>
269 emphasis
270 \u201d \u2019
271 <emphasis>
272 emphasis
273 \u2019 \xbb
274 <emphasis>
275 emphasis
276 \xbb \u203a
277 <emphasis>
278 emphasis
279 \u203a Swedish, Finnish,
280 \u201e
281 <emphasis>
282 emphasis
283 \u201d \u201a
284 <emphasis>
285 emphasis
286 \u2019 Polish,
287 \u201e
288 <emphasis>
289 emphasis
290 \u201d \xbb
291 <emphasis>
292 emphasis
293 \xab \u2019
294 <emphasis>
295 emphasis
296 \u2019 Hungarian,
297 """],
298 [r"""
299 Emphasized asterisk: *\**
300
301 Emphasized double asterisk: *\***
302 """,
303 """\
304 <document source="test data">
305 <paragraph>
306 Emphasized asterisk: \n\
307 <emphasis>
308 *
309 <paragraph>
310 Emphasized double asterisk: \n\
311 <emphasis>
312 **
313 """],
314 ]
315
316 totest['strong'] = [
317 ["""\
318 **strong**
319 """,
320 """\
321 <document source="test data">
322 <paragraph>
323 <strong>
324 strong
325 """],
326 ["""\
327 l'**strong** and l\u2019**strong** with apostrophe
328 """,
329 """\
330 <document source="test data">
331 <paragraph>
332 l'
333 <strong>
334 strong
335 and l\u2019
336 <strong>
337 strong
338 with apostrophe
339 """],
340 ["""\
341 quoted '**strong**', quoted "**strong**",
342 quoted \u2018**strong**\u2019, quoted \u201c**strong**\u201d,
343 quoted \xab**strong**\xbb
344 """,
345 """\
346 <document source="test data">
347 <paragraph>
348 quoted '
349 <strong>
350 strong
351 ', quoted "
352 <strong>
353 strong
354 ",
355 quoted \u2018
356 <strong>
357 strong
358 \u2019, quoted \u201c
359 <strong>
360 strong
361 \u201d,
362 quoted \xab
363 <strong>
364 strong
365 \xbb
366 """],
367 [r"""
368 (**strong**) but not (**) or '(** ' or x**2 or \**kwargs or **
369
370 (however, '**kwargs' will trigger a warning and may be problematic)
371 """,
372 """\
373 <document source="test data">
374 <paragraph>
375 (
376 <strong>
377 strong
378 ) but not (**) or '(** ' or x**2 or **kwargs or **
379 <paragraph>
380 (however, '
381 <problematic ids="problematic-1" refid="system-message-1">
382 **
383 kwargs' will trigger a warning and may be problematic)
384 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="4" source="test data" type="WARNING">
385 <paragraph>
386 Inline strong start-string without end-string.
387 """],
388 ["""\
389 Strong asterisk: *****
390
391 Strong double asterisk: ******
392 """,
393 """\
394 <document source="test data">
395 <paragraph>
396 Strong asterisk: \n\
397 <strong>
398 *
399 <paragraph>
400 Strong double asterisk: \n\
401 <strong>
402 **
403 """],
404 ["""\
405 **strong without closing asterisks
406 """,
407 """\
408 <document source="test data">
409 <paragraph>
410 <problematic ids="problematic-1" refid="system-message-1">
411 **
412 strong without closing asterisks
413 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="1" source="test data" type="WARNING">
414 <paragraph>
415 Inline strong start-string without end-string.
416 """],
417 ]
418
419 totest['literal'] = [
420 ["""\
421 ``literal``
422 """,
423 """\
424 <document source="test data">
425 <paragraph>
426 <literal>
427 literal
428 """],
429 [r"""
430 ``\literal``
431 """,
432 """\
433 <document source="test data">
434 <paragraph>
435 <literal>
436 \\literal
437 """],
438 [r"""
439 ``lite\ral``
440 """,
441 """\
442 <document source="test data">
443 <paragraph>
444 <literal>
445 lite\\ral
446 """],
447 [r"""
448 ``literal\``
449 """,
450 """\
451 <document source="test data">
452 <paragraph>
453 <literal>
454 literal\\
455 """],
456 ["""\
457 l'``literal`` and l\u2019``literal`` with apostrophe
458 """,
459 """\
460 <document source="test data">
461 <paragraph>
462 l'
463 <literal>
464 literal
465 and l\u2019
466 <literal>
467 literal
468 with apostrophe
469 """],
470 ["""\
471 quoted '``literal``', quoted "``literal``",
472 quoted \u2018``literal``\u2019, quoted \u201c``literal``\u201d,
473 quoted \xab``literal``\xbb
474 """,
475 """\
476 <document source="test data">
477 <paragraph>
478 quoted '
479 <literal>
480 literal
481 ', quoted "
482 <literal>
483 literal
484 ",
485 quoted \u2018
486 <literal>
487 literal
488 \u2019, quoted \u201c
489 <literal>
490 literal
491 \u201d,
492 quoted \xab
493 <literal>
494 literal
495 \xbb
496 """],
497 ["""\
498 ``'literal'`` with quotes, ``"literal"`` with quotes,
499 ``\u2018literal\u2019`` with quotes, ``\u201cliteral\u201d`` with quotes,
500 ``\xabliteral\xbb`` with quotes
501 """,
502 """\
503 <document source="test data">
504 <paragraph>
505 <literal>
506 'literal'
507 with quotes, \n\
508 <literal>
509 "literal"
510 with quotes,
511 <literal>
512 \u2018literal\u2019
513 with quotes, \n\
514 <literal>
515 \u201cliteral\u201d
516 with quotes,
517 <literal>
518 \xabliteral\xbb
519 with quotes
520 """],
521 [r"""
522 ``literal ``TeX quotes'' & \backslash`` but not "``" or ``
523
524 (however, ``standalone TeX quotes'' will trigger a warning
525 and may be problematic)
526 """,
527 """\
528 <document source="test data">
529 <paragraph>
530 <literal>
531 literal ``TeX quotes'' & \\backslash
532 but not "``" or ``
533 <paragraph>
534 (however, \n\
535 <problematic ids="problematic-1" refid="system-message-1">
536 ``
537 standalone TeX quotes'' will trigger a warning
538 and may be problematic)
539 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="4" source="test data" type="WARNING">
540 <paragraph>
541 Inline literal start-string without end-string.
542 """],
543 ["""\
544 Find the ```interpreted text``` in this paragraph!
545 """,
546 """\
547 <document source="test data">
548 <paragraph>
549 Find the \n\
550 <literal>
551 `interpreted text`
552 in this paragraph!
553 """],
554 ["""\
555 ``literal without closing backquotes
556 """,
557 """\
558 <document source="test data">
559 <paragraph>
560 <problematic ids="problematic-1" refid="system-message-1">
561 ``
562 literal without closing backquotes
563 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="1" source="test data" type="WARNING">
564 <paragraph>
565 Inline literal start-string without end-string.
566 """],
567 [r"""
568 Python ``list``\s use square bracket syntax.
569 """,
570 """\
571 <document source="test data">
572 <paragraph>
573 Python \n\
574 <literal>
575 list
576 s use square bracket syntax.
577 """],
578 [r"""
579 Blank after opening `` not allowed.
580 """,
581 """\
582 <document source="test data">
583 <paragraph>
584 Blank after opening `` not allowed.
585 """],
586 [r"""
587 no blank ``after closing``continues`` literal.
588 """,
589 """\
590 <document source="test data">
591 <paragraph>
592 no blank \n\
593 <literal>
594 after closing``continues
595 literal.
596 """],
597 [r"""
598 dot ``after closing``. is possible.
599 """,
600 """\
601 <document source="test data">
602 <paragraph>
603 dot \n\
604 <literal>
605 after closing
606 . is possible.
607 """],
608 ]
609
610 totest['references'] = [
611 ["""\
612 ref_
613 """,
614 """\
615 <document source="test data">
616 <paragraph>
617 <reference name="ref" refname="ref">
618 ref
619 """],
620 ["""\
621 l'ref_ and l\u2019ref_ with apostrophe
622 """,
623 """\
624 <document source="test data">
625 <paragraph>
626 l'
627 <reference name="ref" refname="ref">
628 ref
629 and l\u2019
630 <reference name="ref" refname="ref">
631 ref
632 with apostrophe
633 """],
634 ["""\
635 quoted 'ref_', quoted "ref_",
636 quoted \u2018ref_\u2019, quoted \u201cref_\u201d,
637 quoted \xabref_\xbb,
638 but not 'ref ref'_, "ref ref"_, \u2018ref ref\u2019_,
639 \u201cref ref\u201d_, or \xabref ref\xbb_
640 """,
641 """\
642 <document source="test data">
643 <paragraph>
644 quoted '
645 <reference name="ref" refname="ref">
646 ref
647 ', quoted "
648 <reference name="ref" refname="ref">
649 ref
650 ",
651 quoted \u2018
652 <reference name="ref" refname="ref">
653 ref
654 \u2019, quoted \u201c
655 <reference name="ref" refname="ref">
656 ref
657 \u201d,
658 quoted \xab
659 <reference name="ref" refname="ref">
660 ref
661 \xbb,
662 but not 'ref ref'_, "ref ref"_, \u2018ref ref\u2019_,
663 \u201cref ref\u201d_, or \xabref ref\xbb_
664 """],
665 ["""\
666 ref__
667 """,
668 """\
669 <document source="test data">
670 <paragraph>
671 <reference anonymous="1" name="ref">
672 ref
673 """],
674 ["""\
675 l'ref__ and l\u2019ref__ with apostrophe
676 """,
677 """\
678 <document source="test data">
679 <paragraph>
680 l'
681 <reference anonymous="1" name="ref">
682 ref
683 and l\u2019
684 <reference anonymous="1" name="ref">
685 ref
686 with apostrophe
687 """],
688 ["""\
689 quoted 'ref__', quoted "ref__",
690 quoted \u2018ref__\u2019, quoted \u201cref__\u201d,
691 quoted \xabref__\xbb,
692 but not 'ref ref'__, "ref ref"__, \u2018ref ref\u2019__,
693 \u201cref ref\u201d__, or \xabref ref\xbb__
694 """,
695 """\
696 <document source="test data">
697 <paragraph>
698 quoted '
699 <reference anonymous="1" name="ref">
700 ref
701 ', quoted "
702 <reference anonymous="1" name="ref">
703 ref
704 ",
705 quoted \u2018
706 <reference anonymous="1" name="ref">
707 ref
708 \u2019, quoted \u201c
709 <reference anonymous="1" name="ref">
710 ref
711 \u201d,
712 quoted \xab
713 <reference anonymous="1" name="ref">
714 ref
715 \xbb,
716 but not 'ref ref'__, "ref ref"__, \u2018ref ref\u2019__,
717 \u201cref ref\u201d__, or \xabref ref\xbb__
718 """],
719 ["""\
720 ref_, r_, r_e-f_, -ref_, and anonymousref__,
721 but not _ref_ or __attr__ or object.__attr__
722 """,
723 """\
724 <document source="test data">
725 <paragraph>
726 <reference name="ref" refname="ref">
727 ref
728 , \n\
729 <reference name="r" refname="r">
730 r
731 , \n\
732 <reference name="r_e-f" refname="r_e-f">
733 r_e-f
734 , -
735 <reference name="ref" refname="ref">
736 ref
737 , and \n\
738 <reference anonymous="1" name="anonymousref">
739 anonymousref
740 ,
741 but not _ref_ or __attr__ or object.__attr__
742 """],
743 ]
744
745 totest['phrase_references'] = [
746 ["""\
747 `phrase reference`_
748 """,
749 """\
750 <document source="test data">
751 <paragraph>
752 <reference name="phrase reference" refname="phrase reference">
753 phrase reference
754 """],
755 ["""\
756 l'`phrase reference`_ and l\u2019`phrase reference`_ with apostrophe
757 """,
758 """\
759 <document source="test data">
760 <paragraph>
761 l'
762 <reference name="phrase reference" refname="phrase reference">
763 phrase reference
764 and l\u2019
765 <reference name="phrase reference" refname="phrase reference">
766 phrase reference
767 with apostrophe
768 """],
769 ["""\
770 quoted '`phrase reference`_', quoted "`phrase reference`_",
771 quoted \u2018`phrase reference`_\u2019,
772 quoted \u201c`phrase reference`_\u201d,
773 quoted \xab`phrase reference`_\xbb
774 """,
775 """\
776 <document source="test data">
777 <paragraph>
778 quoted '
779 <reference name="phrase reference" refname="phrase reference">
780 phrase reference
781 ', quoted "
782 <reference name="phrase reference" refname="phrase reference">
783 phrase reference
784 ",
785 quoted \u2018
786 <reference name="phrase reference" refname="phrase reference">
787 phrase reference
788 \u2019,
789 quoted \u201c
790 <reference name="phrase reference" refname="phrase reference">
791 phrase reference
792 \u201d,
793 quoted \xab
794 <reference name="phrase reference" refname="phrase reference">
795 phrase reference
796 \xbb
797 """],
798 ["""\
799 `'phrase reference'`_ with quotes, `"phrase reference"`_ with quotes,
800 `\u2018phrase reference\u2019`_ with quotes,
801 `\u201cphrase reference\u201d`_ with quotes,
802 `\xabphrase reference\xbb`_ with quotes
803 """,
804 """\
805 <document source="test data">
806 <paragraph>
807 <reference name="'phrase reference'" refname="'phrase reference'">
808 'phrase reference'
809 with quotes, \n\
810 <reference name=""phrase reference"" refname=""phrase reference"">
811 "phrase reference"
812 with quotes,
813 <reference name="\u2018phrase reference\u2019" refname="\u2018phrase reference\u2019">
814 \u2018phrase reference\u2019
815 with quotes,
816 <reference name="\u201cphrase reference\u201d" refname="\u201cphrase reference\u201d">
817 \u201cphrase reference\u201d
818 with quotes,
819 <reference name="\xabphrase reference\xbb" refname="\xabphrase reference\xbb">
820 \xabphrase reference\xbb
821 with quotes
822 """],
823 ["""\
824 `anonymous reference`__
825 """,
826 """\
827 <document source="test data">
828 <paragraph>
829 <reference anonymous="1" name="anonymous reference">
830 anonymous reference
831 """],
832 ["""\
833 l'`anonymous reference`__ and l\u2019`anonymous reference`__ with apostrophe
834 """,
835 """\
836 <document source="test data">
837 <paragraph>
838 l'
839 <reference anonymous="1" name="anonymous reference">
840 anonymous reference
841 and l\u2019
842 <reference anonymous="1" name="anonymous reference">
843 anonymous reference
844 with apostrophe
845 """],
846 ["""\
847 quoted '`anonymous reference`__', quoted "`anonymous reference`__",
848 quoted \u2018`anonymous reference`__\u2019,
849 quoted \u201c`anonymous reference`__\u201d,
850 quoted \xab`anonymous reference`__\xbb
851 """,
852 """\
853 <document source="test data">
854 <paragraph>
855 quoted '
856 <reference anonymous="1" name="anonymous reference">
857 anonymous reference
858 ', quoted "
859 <reference anonymous="1" name="anonymous reference">
860 anonymous reference
861 ",
862 quoted \u2018
863 <reference anonymous="1" name="anonymous reference">
864 anonymous reference
865 \u2019,
866 quoted \u201c
867 <reference anonymous="1" name="anonymous reference">
868 anonymous reference
869 \u201d,
870 quoted \xab
871 <reference anonymous="1" name="anonymous reference">
872 anonymous reference
873 \xbb
874 """],
875 ["""\
876 `'anonymous reference'`__ with quotes, `"anonymous reference"`__ with quotes,
877 `\u2018anonymous reference\u2019`__ with quotes,
878 `\u201canonymous reference\u201d`__ with quotes,
879 `\xabanonymous reference\xbb`__ with quotes
880 """,
881 """\
882 <document source="test data">
883 <paragraph>
884 <reference anonymous="1" name="'anonymous reference'">
885 'anonymous reference'
886 with quotes, \n\
887 <reference anonymous="1" name=""anonymous reference"">
888 "anonymous reference"
889 with quotes,
890 <reference anonymous="1" name="\u2018anonymous reference\u2019">
891 \u2018anonymous reference\u2019
892 with quotes,
893 <reference anonymous="1" name="\u201canonymous reference\u201d">
894 \u201canonymous reference\u201d
895 with quotes,
896 <reference anonymous="1" name="\xabanonymous reference\xbb">
897 \xabanonymous reference\xbb
898 with quotes
899 """],
900 ["""\
901 `phrase reference
902 across lines`_
903 """,
904 """\
905 <document source="test data">
906 <paragraph>
907 <reference name="phrase reference across lines" refname="phrase reference across lines">
908 phrase reference
909 across lines
910 """],
911 ["""\
912 `phrase\\`_ reference`_
913 """,
914 """\
915 <document source="test data">
916 <paragraph>
917 <reference name="phrase`_ reference" refname="phrase`_ reference">
918 phrase`_ reference
919 """],
920 ["""\
921 Invalid phrase reference:
922
923 :role:`phrase reference`_
924 """,
925 """\
926 <document source="test data">
927 <paragraph>
928 Invalid phrase reference:
929 <paragraph>
930 <problematic ids="problematic-1" refid="system-message-1">
931 :role:`phrase reference`_
932 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="3" source="test data" type="WARNING">
933 <paragraph>
934 Mismatch: both interpreted text role prefix and reference suffix.
935 """],
936 ["""\
937 Invalid phrase reference:
938
939 `phrase reference`:role:_
940 """,
941 """\
942 <document source="test data">
943 <paragraph>
944 Invalid phrase reference:
945 <paragraph>
946 <problematic ids="problematic-1" refid="system-message-1">
947 `phrase reference`:role:_
948 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="3" source="test data" type="WARNING">
949 <paragraph>
950 Mismatch: both interpreted text role suffix and reference suffix.
951 """],
952 ["""\
953 `phrase reference_ without closing backquote
954 """,
955 """\
956 <document source="test data">
957 <paragraph>
958 <problematic ids="problematic-1" refid="system-message-1">
959 `
960 phrase \n\
961 <reference name="reference" refname="reference">
962 reference
963 without closing backquote
964 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="1" source="test data" type="WARNING">
965 <paragraph>
966 Inline interpreted text or phrase reference start-string without end-string.
967 """],
968 ["""\
969 `anonymous phrase reference__ without closing backquote
970 """,
971 """\
972 <document source="test data">
973 <paragraph>
974 <problematic ids="problematic-1" refid="system-message-1">
975 `
976 anonymous phrase \n\
977 <reference anonymous="1" name="reference">
978 reference
979 without closing backquote
980 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="1" source="test data" type="WARNING">
981 <paragraph>
982 Inline interpreted text or phrase reference start-string without end-string.
983 """],
984 ]
985
986 totest['embedded_uris'] = [
987 ["""\
988 `phrase reference <http://example.com>`_
989 """,
990 """\
991 <document source="test data">
992 <paragraph>
993 <reference name="phrase reference" refuri="http://example.com">
994 phrase reference
995 <target names="phrase\\ reference" refuri="http://example.com">
996 """],
997 ["""\
998 `anonymous reference <http://example.com>`__
999 """,
1000 """\
1001 <document source="test data">
1002 <paragraph>
1003 <reference name="anonymous reference" refuri="http://example.com">
1004 anonymous reference
1005 """],
1006 ["""\
1007 `embedded URI on next line
1008 <http://example.com>`__
1009 """,
1010 """\
1011 <document source="test data">
1012 <paragraph>
1013 <reference name="embedded URI on next line" refuri="http://example.com">
1014 embedded URI on next line
1015 """],
1016 ["""\
1017 `embedded URI across lines <http://example.com/
1018 long/path>`__
1019 """,
1020 """\
1021 <document source="test data">
1022 <paragraph>
1023 <reference name="embedded URI across lines" refuri="http://example.com/long/path">
1024 embedded URI across lines
1025 """],
1026 ["""\
1027 `embedded URI with whitespace <http://example.com/
1028 long/path /and /whitespace>`__
1029 """,
1030 """\
1031 <document source="test data">
1032 <paragraph>
1033 <reference name="embedded URI with whitespace" refuri="http://example.com/long/path/and/whitespace">
1034 embedded URI with whitespace
1035 """],
1036 [r"""
1037 `embedded URI with escaped whitespace <http://example.com/a\
1038 long/path\ and/some\ escaped\ whitespace>`__
1039
1040 `<omitted\ reference\ text\ with\ escaped\ whitespace>`__
1041 """,
1042 """\
1043 <document source="test data">
1044 <paragraph>
1045 <reference name="embedded URI with escaped whitespace" refuri="http://example.com/a long/path and/some escaped whitespace">
1046 embedded URI with escaped whitespace
1047 <paragraph>
1048 <reference name="omitted reference text with escaped whitespace" refuri="omitted reference text with escaped whitespace">
1049 omitted reference text with escaped whitespace
1050 """],
1051 ["""\
1052 `embedded email address <[email protected]>`__
1053
1054 `embedded email address broken across lines <jdoe
1055 @example.com>`__
1056 """,
1057 """\
1058 <document source="test data">
1059 <paragraph>
1060 <reference name="embedded email address" refuri="mailto:[email protected]">
1061 embedded email address
1062 <paragraph>
1063 <reference name="embedded email address broken across lines" refuri="mailto:[email protected]">
1064 embedded email address broken across lines
1065 """],
1066 [r"""
1067 `embedded URI with too much whitespace < http://example.com/
1068 long/path /and /whitespace >`__
1069
1070 `embedded URI with too much whitespace at end <http://example.com/
1071 long/path /and /whitespace >`__
1072
1073 `embedded URI with no preceding whitespace<http://example.com>`__
1074
1075 `escaped URI \<http://example.com>`__
1076
1077 See `HTML Anchors: \<a>`_.
1078 """,
1079 """\
1080 <document source="test data">
1081 <paragraph>
1082 <reference anonymous="1" name="embedded URI with too much whitespace < http://example.com/ long/path /and /whitespace >">
1083 embedded URI with too much whitespace < http://example.com/
1084 long/path /and /whitespace >
1085 <paragraph>
1086 <reference anonymous="1" name="embedded URI with too much whitespace at end <http://example.com/ long/path /and /whitespace >">
1087 embedded URI with too much whitespace at end <http://example.com/
1088 long/path /and /whitespace >
1089 <paragraph>
1090 <reference anonymous="1" name="embedded URI with no preceding whitespace<http://example.com>">
1091 embedded URI with no preceding whitespace<http://example.com>
1092 <paragraph>
1093 <reference anonymous="1" name="escaped URI <http://example.com>">
1094 escaped URI <http://example.com>
1095 <paragraph>
1096 See \n\
1097 <reference name="HTML Anchors: <a>" refname="html anchors: <a>">
1098 HTML Anchors: <a>
1099 .
1100 """],
1101 ["""\
1102 Relative URIs' reference text can be omitted:
1103
1104 `<reference>`_
1105
1106 `<anonymous>`__
1107 """,
1108 """\
1109 <document source="test data">
1110 <paragraph>
1111 Relative URIs' reference text can be omitted:
1112 <paragraph>
1113 <reference name="reference" refuri="reference">
1114 reference
1115 <target names="reference" refuri="reference">
1116 <paragraph>
1117 <reference name="anonymous" refuri="anonymous">
1118 anonymous
1119 """],
1120 [r"""
1121 Escape trailing low-line char in URIs:
1122
1123 `<reference\_>`_
1124
1125 `<anonymous\_>`__
1126 """,
1127 """\
1128 <document source="test data">
1129 <paragraph>
1130 Escape trailing low-line char in URIs:
1131 <paragraph>
1132 <reference name="reference_" refuri="reference_">
1133 reference_
1134 <target names="reference_" refuri="reference_">
1135 <paragraph>
1136 <reference name="anonymous_" refuri="anonymous_">
1137 anonymous_
1138 """],
1139 ["""\
1140 Escape other char in URIs:
1141
1142 `<reference\\:1>`_
1143
1144 `<anonymous\\call>`__
1145 """,
1146 """\
1147 <document source="test data">
1148 <paragraph>
1149 Escape other char in URIs:
1150 <paragraph>
1151 <reference name="reference:1" refuri="reference:1">
1152 reference:1
1153 <target names="reference:1" refuri="reference:1">
1154 <paragraph>
1155 <reference name="anonymouscall" refuri="anonymouscall">
1156 anonymouscall
1157 """],
1158 ["""\
1159 Report duplicate refname.
1160
1161 Explicit targets: _`file.txt`, _`file.html`.
1162
1163 Embedded URI: named `<file.txt>`_ and anonymous `<file.html>`__.
1164 """,
1165 """\
1166 <document source="test data">
1167 <paragraph>
1168 Report duplicate refname.
1169 <paragraph>
1170 Explicit targets: \n\
1171 <target ids="file-txt" names="file.txt">
1172 file.txt
1173 , \n\
1174 <target ids="file-html" names="file.html">
1175 file.html
1176 .
1177 <system_message level="1" line="6" source="test data" type="INFO">
1178 <paragraph>
1179 Duplicate implicit target name: "file.txt".
1180 <paragraph>
1181 Embedded URI: named \n\
1182 <reference name="file.txt" refuri="file.txt">
1183 file.txt
1184 <target dupnames="file.txt" refuri="file.txt">
1185 and anonymous \n\
1186 <reference name="file.html" refuri="file.html">
1187 file.html
1188 .
1189 """],
1190 ]
1191
1192 totest['embedded_aliases'] = [
1193 ["""\
1194 `phrase reference <alias_>`_
1195 """,
1196 """\
1197 <document source="test data">
1198 <paragraph>
1199 <reference name="phrase reference" refname="alias">
1200 phrase reference
1201 <target names="phrase\\ reference" refname="alias">
1202 """],
1203 ["""\
1204 `anonymous reference <alias_>`__
1205 """,
1206 """\
1207 <document source="test data">
1208 <paragraph>
1209 <reference name="anonymous reference" refname="alias">
1210 anonymous reference
1211 """],
1212 ["""\
1213 `embedded alias on next line
1214 <alias_>`__
1215 """,
1216 """\
1217 <document source="test data">
1218 <paragraph>
1219 <reference name="embedded alias on next line" refname="alias">
1220 embedded alias on next line
1221 """],
1222 ["""\
1223 `embedded alias across lines <alias
1224 phrase_>`__
1225 """,
1226 """\
1227 <document source="test data">
1228 <paragraph>
1229 <reference name="embedded alias across lines" refname="alias phrase">
1230 embedded alias across lines
1231 """],
1232 ["""\
1233 `embedded alias with whitespace <alias
1234 long phrase_>`__
1235 """,
1236 """\
1237 <document source="test data">
1238 <paragraph>
1239 <reference name="embedded alias with whitespace" refname="alias long phrase">
1240 embedded alias with whitespace
1241 """],
1242 ["""\
1243 `<embedded alias with whitespace_>`__
1244 """,
1245 """\
1246 <document source="test data">
1247 <paragraph>
1248 <reference name="embedded alias with whitespace" refname="embedded alias with whitespace">
1249 embedded alias with whitespace
1250 """],
1251 [r"""
1252 `no embedded alias (whitespace inside bracket) < alias_ >`__
1253
1254 `no embedded alias (no preceding whitespace)<alias_>`__
1255 """,
1256 """\
1257 <document source="test data">
1258 <paragraph>
1259 <reference anonymous="1" name="no embedded alias (whitespace inside bracket) < alias_ >">
1260 no embedded alias (whitespace inside bracket) < alias_ >
1261 <paragraph>
1262 <reference anonymous="1" name="no embedded alias (no preceding whitespace)<alias_>">
1263 no embedded alias (no preceding whitespace)<alias_>
1264 """],
1265 [r"""
1266 `anonymous reference <alias\ with\\ escaped \:characters_>`__
1267 """,
1268 """\
1269 <document source="test data">
1270 <paragraph>
1271 <reference name="anonymous reference" refname="aliaswith\\ escaped :characters">
1272 anonymous reference
1273 """],
1274 [r"""
1275 `anonymous reference <alias\ with\\ escaped \:characters_>`__
1276 """,
1277 """\
1278 <document source="test data">
1279 <paragraph>
1280 <reference name="anonymous reference" refname="aliaswith\\ escaped :characters">
1281 anonymous reference
1282 """],
1283 ["""\
1284 Duplicate refnames in references with embedded alias.
1285
1286 Explicit targets: _`tg1` and _`tg2`.
1287
1288 References with embedded alias: `link <tg1_>`_ and `link <tg2_>`_.
1289
1290 No clash with anonymous reference `link <tg1_>`__.
1291 """,
1292 """\
1293 <document source="test data">
1294 <paragraph>
1295 Duplicate refnames in references with embedded alias.
1296 <paragraph>
1297 Explicit targets: \n\
1298 <target ids="tg1" names="tg1">
1299 tg1
1300 and \n\
1301 <target ids="tg2" names="tg2">
1302 tg2
1303 .
1304 <system_message level="1" line="6" source="test data" type="INFO">
1305 <paragraph>
1306 Duplicate implicit target name: "link".
1307 <paragraph>
1308 References with embedded alias: \n\
1309 <reference name="link" refname="tg1">
1310 link
1311 <target dupnames="link" ids="link-1" refname="tg1">
1312 and \n\
1313 <reference name="link" refname="tg2">
1314 link
1315 <target dupnames="link" refname="tg2">
1316 .
1317 <paragraph>
1318 No clash with anonymous reference \n\
1319 <reference name="link" refname="tg1">
1320 link
1321 .
1322 """],
1323 ]
1324
1325 totest['inline_targets'] = [
1326 ["""\
1327 _`target`
1328
1329 Here is _`another target` in some text. And _`yet
1330 another target`, spanning lines.
1331
1332 _`Here is a TaRgeT` with case and spacial difficulties.
1333 """,
1334 """\
1335 <document source="test data">
1336 <paragraph>
1337 <target ids="target" names="target">
1338 target
1339 <paragraph>
1340 Here is \n\
1341 <target ids="another-target" names="another\\ target">
1342 another target
1343 in some text. And \n\
1344 <target ids="yet-another-target" names="yet\\ another\\ target">
1345 yet
1346 another target
1347 , spanning lines.
1348 <paragraph>
1349 <target ids="here-is-a-target" names="here\\ is\\ a\\ target">
1350 Here is a TaRgeT
1351 with case and spacial difficulties.
1352 """],
1353 ["""\
1354 l'_`target1` and l\u2019_`target2` with apostrophe
1355 """,
1356 """\
1357 <document source="test data">
1358 <paragraph>
1359 l'
1360 <target ids="target1" names="target1">
1361 target1
1362 and l\u2019
1363 <target ids="target2" names="target2">
1364 target2
1365 with apostrophe
1366 """],
1367 ["""\
1368 quoted '_`target1`', quoted "_`target2`",
1369 quoted \u2018_`target3`\u2019, quoted \u201c_`target4`\u201d,
1370 quoted \xab_`target5`\xbb
1371 """,
1372 """\
1373 <document source="test data">
1374 <paragraph>
1375 quoted '
1376 <target ids="target1" names="target1">
1377 target1
1378 ', quoted "
1379 <target ids="target2" names="target2">
1380 target2
1381 ",
1382 quoted \u2018
1383 <target ids="target3" names="target3">
1384 target3
1385 \u2019, quoted \u201c
1386 <target ids="target4" names="target4">
1387 target4
1388 \u201d,
1389 quoted \xab
1390 <target ids="target5" names="target5">
1391 target5
1392 \xbb
1393 """],
1394 ["""\
1395 _`'target1'` with quotes, _`"target2"` with quotes,
1396 _`\u2018target3\u2019` with quotes, _`\u201ctarget4\u201d` with quotes,
1397 _`\xabtarget5\xbb` with quotes
1398 """,
1399 """\
1400 <document source="test data">
1401 <paragraph>
1402 <target ids="target1" names="'target1'">
1403 'target1'
1404 with quotes, \n\
1405 <target ids="target2" names=""target2"">
1406 "target2"
1407 with quotes,
1408 <target ids="target3" names="\u2018target3\u2019">
1409 \u2018target3\u2019
1410 with quotes, \n\
1411 <target ids="target4" names="\u201ctarget4\u201d">
1412 \u201ctarget4\u201d
1413 with quotes,
1414 <target ids="target5" names="\xabtarget5\xbb">
1415 \xabtarget5\xbb
1416 with quotes
1417 """],
1418 ["""\
1419 But this isn't a _target; targets require backquotes.
1420
1421 And _`this`_ is just plain confusing.
1422 """,
1423 """\
1424 <document source="test data">
1425 <paragraph>
1426 But this isn't a _target; targets require backquotes.
1427 <paragraph>
1428 And \n\
1429 <problematic ids="problematic-1" refid="system-message-1">
1430 _`
1431 this`_ is just plain confusing.
1432 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="3" source="test data" type="WARNING">
1433 <paragraph>
1434 Inline target start-string without end-string.
1435 """],
1436 ["""\
1437 _`inline target without closing backquote
1438 """,
1439 """\
1440 <document source="test data">
1441 <paragraph>
1442 <problematic ids="problematic-1" refid="system-message-1">
1443 _`
1444 inline target without closing backquote
1445 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="1" source="test data" type="WARNING">
1446 <paragraph>
1447 Inline target start-string without end-string.
1448 """],
1449 ]
1450
1451 totest['footnote_reference'] = [
1452 ["""\
1453 [1]_
1454 """,
1455 """\
1456 <document source="test data">
1457 <paragraph>
1458 <footnote_reference ids="footnote-reference-1" refname="1">
1459 1
1460 """],
1461 ["""\
1462 [#]_
1463 """,
1464 """\
1465 <document source="test data">
1466 <paragraph>
1467 <footnote_reference auto="1" ids="footnote-reference-1">
1468 """],
1469 ["""\
1470 [#label]_
1471 """,
1472 """\
1473 <document source="test data">
1474 <paragraph>
1475 <footnote_reference auto="1" ids="footnote-reference-1" refname="label">
1476 """],
1477 ["""\
1478 [*]_
1479 """,
1480 """\
1481 <document source="test data">
1482 <paragraph>
1483 <footnote_reference auto="*" ids="footnote-reference-1">
1484 """],
1485 ["""\
1486 Adjacent footnote refs are not possible: [*]_[#label]_ [#]_[2]_ [1]_[*]_
1487 """,
1488 """\
1489 <document source="test data">
1490 <paragraph>
1491 Adjacent footnote refs are not possible: [*]_[#label]_ [#]_[2]_ [1]_[*]_
1492 """],
1493 ]
1494
1495 totest['citation_reference'] = [
1496 ["""\
1497 [citation]_
1498 """,
1499 """\
1500 <document source="test data">
1501 <paragraph>
1502 <citation_reference ids="citation-reference-1" refname="citation">
1503 citation
1504 """],
1505 ["""\
1506 [citation]_ and [cit-ation]_ and [cit.ation]_ and [CIT1]_ but not [CIT 1]_
1507 """,
1508 """\
1509 <document source="test data">
1510 <paragraph>
1511 <citation_reference ids="citation-reference-1" refname="citation">
1512 citation
1513 and \n\
1514 <citation_reference ids="citation-reference-2" refname="cit-ation">
1515 cit-ation
1516 and \n\
1517 <citation_reference ids="citation-reference-3" refname="cit.ation">
1518 cit.ation
1519 and \n\
1520 <citation_reference ids="citation-reference-4" refname="cit1">
1521 CIT1
1522 but not [CIT 1]_
1523 """],
1524 ["""\
1525 Adjacent citation refs are not possible: [citation]_[CIT1]_
1526 """,
1527 """\
1528 <document source="test data">
1529 <paragraph>
1530 Adjacent citation refs are not possible: [citation]_[CIT1]_
1531 """],
1532 ]
1533
1534 totest['substitution_references'] = [
1535 ["""\
1536 |subref|
1537 """,
1538 """\
1539 <document source="test data">
1540 <paragraph>
1541 <substitution_reference refname="subref">
1542 subref
1543 """],
1544 ["""\
1545 |subref|_ and |subref|__
1546 """,
1547 """\
1548 <document source="test data">
1549 <paragraph>
1550 <reference refname="subref">
1551 <substitution_reference refname="subref">
1552 subref
1553 and \n\
1554 <reference anonymous="1">
1555 <substitution_reference refname="subref">
1556 subref
1557 """],
1558 ["""\
1559 |substitution reference|
1560 """,
1561 """\
1562 <document source="test data">
1563 <paragraph>
1564 <substitution_reference refname="substitution reference">
1565 substitution reference
1566 """],
1567 ["""\
1568 |substitution
1569 reference|
1570 """,
1571 """\
1572 <document source="test data">
1573 <paragraph>
1574 <substitution_reference refname="substitution reference">
1575 substitution
1576 reference
1577 """],
1578 ["""\
1579 |substitution reference without closing verbar
1580 """,
1581 """\
1582 <document source="test data">
1583 <paragraph>
1584 <problematic ids="problematic-1" refid="system-message-1">
1585 |
1586 substitution reference without closing verbar
1587 <system_message backrefs="problematic-1" ids="system-message-1" level="2" line="1" source="test data" type="WARNING">
1588 <paragraph>
1589 Inline substitution_reference start-string without end-string.
1590 """],
1591 ["""\
1592 first | then || and finally |||
1593 """,
1594 """\
1595 <document source="test data">
1596 <paragraph>
1597 first | then || and finally |||
1598 """],
1599 ["""\
1600 Substitution reference with |mix|.
1601
1602 .. |mix| replace:: text and hyperlink-reference_
1603 """,
1604 """\
1605 <document source="test data">
1606 <paragraph>
1607 Substitution reference with \n\
1608 <substitution_reference refname="mix">
1609 mix
1610 .
1611 <substitution_definition names="mix">
1612 text and \n\
1613 <reference name="hyperlink-reference" refname="hyperlink-reference">
1614 hyperlink-reference
1615 """],
1616 ]
1617
1618 totest['standalone_hyperlink'] = [
1619 ["""\
1620 http://www.standalone.hyperlink.com
1621
1622 http:/one-slash-only.absolute.path
1623
1624 [http://example.com]
1625
1626 (http://example.com)
1627
1628 <http://example.com>
1629
1630 http://[1080:0:0:0:8:800:200C:417A]/IPv6address.html
1631
1632 http://[3ffe:2a00:100:7031::1] (the final "]" is ambiguous in text)
1633
1634 http://[3ffe:2a00:100:7031::1]/
1635
1636 mailto:[email protected]
1637
1638 news:comp.lang.python
1639
1640 An email address in a sentence: [email protected].
1641
1642 ftp://ends.with.a.period.
1643
1644 (a.question.mark@end?)
1645 """,
1646 """\
1647 <document source="test data">
1648 <paragraph>
1649 <reference refuri="http://www.standalone.hyperlink.com">
1650 http://www.standalone.hyperlink.com
1651 <paragraph>
1652 <reference refuri="http:/one-slash-only.absolute.path">
1653 http:/one-slash-only.absolute.path
1654 <paragraph>
1655 [
1656 <reference refuri="http://example.com">
1657 http://example.com
1658 ]
1659 <paragraph>
1660 (
1661 <reference refuri="http://example.com">
1662 http://example.com
1663 )
1664 <paragraph>
1665 <
1666 <reference refuri="http://example.com">
1667 http://example.com
1668 >
1669 <paragraph>
1670 <reference refuri="http://[1080:0:0:0:8:800:200C:417A]/IPv6address.html">
1671 http://[1080:0:0:0:8:800:200C:417A]/IPv6address.html
1672 <paragraph>
1673 <reference refuri="http://[3ffe:2a00:100:7031::1">
1674 http://[3ffe:2a00:100:7031::1
1675 ] (the final "]" is ambiguous in text)
1676 <paragraph>
1677 <reference refuri="http://[3ffe:2a00:100:7031::1]/">
1678 http://[3ffe:2a00:100:7031::1]/
1679 <paragraph>
1680 <reference refuri="mailto:[email protected]">
1681 mailto:[email protected]
1682 <paragraph>
1683 <reference refuri="news:comp.lang.python">
1684 news:comp.lang.python
1685 <paragraph>
1686 An email address in a sentence: \n\
1687 <reference refuri="mailto:[email protected]">
1688 [email protected]
1689 .
1690 <paragraph>
1691 <reference refuri="ftp://ends.with.a.period">
1692 ftp://ends.with.a.period
1693 .
1694 <paragraph>
1695 (
1696 <reference refuri="mailto:a.question.mark@end">
1697 a.question.mark@end
1698 ?)
1699 """],
1700 [r"""
1701 Valid URLs with escaped markup characters:
1702
1703 http://example.com/\*content\*/whatever
1704
1705 http://example.com/\*content*/whatever
1706 """,
1707 """\
1708 <document source="test data">
1709 <paragraph>
1710 Valid URLs with escaped markup characters:
1711 <paragraph>
1712 <reference refuri="http://example.com/*content*/whatever">
1713 http://example.com/*content*/whatever
1714 <paragraph>
1715 <reference refuri="http://example.com/*content*/whatever">
1716 http://example.com/*content*/whatever
1717 """],
1718 ["""\
1719 Valid URLs may end with punctuation inside "<>":
1720
1721 <http://example.org/ends-with-dot.>
1722 """,
1723 """\
1724 <document source="test data">
1725 <paragraph>
1726 Valid URLs may end with punctuation inside "<>":
1727 <paragraph>
1728 <
1729 <reference refuri="http://example.org/ends-with-dot.">
1730 http://example.org/ends-with-dot.
1731 >
1732 """],
1733 ["""\
1734 Valid URLs with interesting endings:
1735
1736 http://example.org/ends-with-pluses++
1737 """,
1738 """\
1739 <document source="test data">
1740 <paragraph>
1741 Valid URLs with interesting endings:
1742 <paragraph>
1743 <reference refuri="http://example.org/ends-with-pluses++">
1744 http://example.org/ends-with-pluses++
1745 """],
1746 ["""\
1747 None of these are standalone hyperlinks (their "schemes"
1748 are not recognized): signal:noise, a:b.
1749 """,
1750 """\
1751 <document source="test data">
1752 <paragraph>
1753 None of these are standalone hyperlinks (their "schemes"
1754 are not recognized): signal:noise, a:b.
1755 """],
1756 ["""\
1757 Escaped email addresses are not recognized: test\\@example.org
1758 """,
1759 """\
1760 <document source="test data">
1761 <paragraph>
1762 Escaped email addresses are not recognized: [email protected]
1763 """],
1764 ]
1765
1766 totest['markup_recognition_rules'] = [
1767 ["""\
1768 __This__ should be left alone.
1769 """,
1770 """\
1771 <document source="test data">
1772 <paragraph>
1773 __This__ should be left alone.
1774 """],
1775 [r"""
1776 Character-level m\ *a*\ **r**\ ``k``\ `u`:title:\p
1777 with backslash-escaped whitespace, including new\
1778 lines.
1779 """,
1780 """\
1781 <document source="test data">
1782 <paragraph>
1783 Character-level m
1784 <emphasis>
1785 a
1786 <strong>
1787 r
1788 <literal>
1789 k
1790 <title_reference>
1791 u
1792 p
1793 with backslash-escaped whitespace, including newlines.
1794 """],
1795 ["""\
1796 text-*separated*\u2010*by*\u2011*various*\u2012*dashes*\u2013*and*\u2014*hyphens*.
1797 \u00bf*punctuation*? \u00a1*examples*!\u00a0*no-break-space*\u00a0.
1798 """,
1799 """\
1800 <document source="test data">
1801 <paragraph>
1802 text-
1803 <emphasis>
1804 separated
1805 \u2010
1806 <emphasis>
1807 by
1808 \u2011
1809 <emphasis>
1810 various
1811 \u2012
1812 <emphasis>
1813 dashes
1814 \u2013
1815 <emphasis>
1816 and
1817 \u2014
1818 <emphasis>
1819 hyphens
1820 .
1821 \xbf
1822 <emphasis>
1823 punctuation
1824 ? \xa1
1825 <emphasis>
1826 examples
1827 !\xa0
1828 <emphasis>
1829 no-break-space
1830 \u00a0.
1831 """],
1832 # Whitespace characters:
1833 # \u180e*MONGOLIAN VOWEL SEPARATOR*\u180e, fails in Python 2.6
1834 ["""\
1835 text separated by
1836 *newline*
1837 or *space* or one of
1838 \xa0*NO-BREAK SPACE*\xa0,
1839 \u1680*OGHAM SPACE MARK*\u1680,
1840 \u2000*EN QUAD*\u2000,
1841 \u2001*EM QUAD*\u2001,
1842 \u2002*EN SPACE*\u2002,
1843 \u2003*EM SPACE*\u2003,
1844 \u2004*THREE-PER-EM SPACE*\u2004,
1845 \u2005*FOUR-PER-EM SPACE*\u2005,
1846 \u2006*SIX-PER-EM SPACE*\u2006,
1847 \u2007*FIGURE SPACE*\u2007,
1848 \u2008*PUNCTUATION SPACE*\u2008,
1849 \u2009*THIN SPACE*\u2009,
1850 \u200a*HAIR SPACE*\u200a,
1851 \u202f*NARROW NO-BREAK SPACE*\u202f,
1852 \u205f*MEDIUM MATHEMATICAL SPACE*\u205f,
1853 \u3000*IDEOGRAPHIC SPACE*\u3000,
1854 \u2028*LINE SEPARATOR*\u2028
1855 """,
1856 """\
1857 <document source="test data">
1858 <paragraph>
1859 text separated by
1860 <emphasis>
1861 newline
1862 \n\
1863 or \n\
1864 <emphasis>
1865 space
1866 or one of
1867 \xa0
1868 <emphasis>
1869 NO-BREAK SPACE
1870 \xa0,
1871 \u1680
1872 <emphasis>
1873 OGHAM SPACE MARK
1874 \u1680,
1875 \u2000
1876 <emphasis>
1877 EN QUAD
1878 \u2000,
1879 \u2001
1880 <emphasis>
1881 EM QUAD
1882 \u2001,
1883 \u2002
1884 <emphasis>
1885 EN SPACE
1886 \u2002,
1887 \u2003
1888 <emphasis>
1889 EM SPACE
1890 \u2003,
1891 \u2004
1892 <emphasis>
1893 THREE-PER-EM SPACE
1894 \u2004,
1895 \u2005
1896 <emphasis>
1897 FOUR-PER-EM SPACE
1898 \u2005,
1899 \u2006
1900 <emphasis>
1901 SIX-PER-EM SPACE
1902 \u2006,
1903 \u2007
1904 <emphasis>
1905 FIGURE SPACE
1906 \u2007,
1907 \u2008
1908 <emphasis>
1909 PUNCTUATION SPACE
1910 \u2008,
1911 \u2009
1912 <emphasis>
1913 THIN SPACE
1914 \u2009,
1915 \u200a
1916 <emphasis>
1917 HAIR SPACE
1918 \u200a,
1919 \u202f
1920 <emphasis>
1921 NARROW NO-BREAK SPACE
1922 \u202f,
1923 \u205f
1924 <emphasis>
1925 MEDIUM MATHEMATICAL SPACE
1926 \u205f,
1927 \u3000
1928 <emphasis>
1929 IDEOGRAPHIC SPACE
1930 \u3000,
1931 <paragraph>
1932 <emphasis>
1933 LINE SEPARATOR
1934 """],
1935 ["""\
1936 inline markup separated by non-ASCII whitespace
1937 \xa0**NO-BREAK SPACE**\xa0, \xa0``NO-BREAK SPACE``\xa0, \xa0`NO-BREAK SPACE`\xa0,
1938 \u2000**EN QUAD**\u2000, \u2000``EN QUAD``\u2000, \u2000`EN QUAD`\u2000,
1939 \u202f**NARROW NBSP**\u202f, \u202f``NARROW NBSP``\u202f, \u202f`NARROW NBSP`\u202f,
1940 """,
1941 """\
1942 <document source="test data">
1943 <paragraph>
1944 inline markup separated by non-ASCII whitespace
1945 \xa0
1946 <strong>
1947 NO-BREAK SPACE
1948 \xa0, \xa0
1949 <literal>
1950 NO-BREAK SPACE
1951 \xa0, \xa0
1952 <title_reference>
1953 NO-BREAK SPACE
1954 \xa0,
1955 \u2000
1956 <strong>
1957 EN QUAD
1958 \u2000, \u2000
1959 <literal>
1960 EN QUAD
1961 \u2000, \u2000
1962 <title_reference>
1963 EN QUAD
1964 \u2000,
1965 \u202f
1966 <strong>
1967 NARROW NBSP
1968 \u202f, \u202f
1969 <literal>
1970 NARROW NBSP
1971 \u202f, \u202f
1972 <title_reference>
1973 NARROW NBSP
1974 \u202f,
1975 """],
1976 ["""\
1977 no inline markup due to whitespace inside and behind: *
1978 newline
1979 *
1980 * space * or one of
1981 *\xa0NO-BREAK SPACE\xa0*
1982 *\u1680OGHAM SPACE MARK\u1680*
1983 *\u2000EN QUAD\u2000*
1984 *\u2001EM QUAD\u2001*
1985 *\u2002EN SPACE\u2002*
1986 *\u2003EM SPACE\u2003*
1987 *\u2004THREE-PER-EM SPACE\u2004*
1988 *\u2005FOUR-PER-EM SPACE\u2005*
1989 *\u2006SIX-PER-EM SPACE\u2006*
1990 *\u2007FIGURE SPACE\u2007*
1991 *\u2008PUNCTUATION SPACE\u2008*
1992 *\u2009THIN SPACE\u2009*
1993 *\u200aHAIR SPACE\u200a*
1994 *\u202fNARROW NO-BREAK SPACE\u202f*
1995 *\u205fMEDIUM MATHEMATICAL SPACE\u205f*
1996 *\u3000IDEOGRAPHIC SPACE\u3000*
1997 *\u2028LINE SEPARATOR\u2028*
1998 """,
1999 """\
2000 <document source="test data">
2001 <paragraph>
2002 no inline markup due to whitespace inside and behind: *
2003 newline
2004 *
2005 * space * or one of
2006 *\xa0NO-BREAK SPACE\xa0*
2007 *\u1680OGHAM SPACE MARK\u1680*
2008 *\u2000EN QUAD\u2000*
2009 *\u2001EM QUAD\u2001*
2010 *\u2002EN SPACE\u2002*
2011 *\u2003EM SPACE\u2003*
2012 *\u2004THREE-PER-EM SPACE\u2004*
2013 *\u2005FOUR-PER-EM SPACE\u2005*
2014 *\u2006SIX-PER-EM SPACE\u2006*
2015 *\u2007FIGURE SPACE\u2007*
2016 *\u2008PUNCTUATION SPACE\u2008*
2017 *\u2009THIN SPACE\u2009*
2018 *\u200aHAIR SPACE\u200a*
2019 *\u202fNARROW NO-BREAK SPACE\u202f*
2020 *\u205fMEDIUM MATHEMATICAL SPACE\u205f*
2021 *\u3000IDEOGRAPHIC SPACE\u3000*
2022 *
2023 LINE SEPARATOR
2024 *
2025 """],
2026 ["""\
2027 no inline markup because of non-ASCII whitespace following /preceding the markup
2028 **\xa0NO-BREAK SPACE\xa0** ``\xa0NO-BREAK SPACE\xa0`` `\xa0NO-BREAK SPACE\xa0`
2029 **\u2000EN QUAD\u2000** ``\u2000EN QUAD\u2000`` `\u2000EN QUAD\u2000`
2030 **\u202fNARROW NBSP\u202f** ``\u202fNARROW NBSP\u202f`` `\u202fNARROW NBSP\u202f`
2031 """,
2032 """\
2033 <document source="test data">
2034 <paragraph>
2035 no inline markup because of non-ASCII whitespace following /preceding the markup
2036 **\xa0NO-BREAK SPACE\xa0** ``\xa0NO-BREAK SPACE\xa0`` `\xa0NO-BREAK SPACE\xa0`
2037 **\u2000EN QUAD\u2000** ``\u2000EN QUAD\u2000`` `\u2000EN QUAD\u2000`
2038 **\u202fNARROW NBSP\u202f** ``\u202fNARROW NBSP\u202f`` `\u202fNARROW NBSP\u202f`
2039 """],
2040 # « * » ‹ * › « * » ‹ * › « * » ‹ * › French,
2041 ["""\
2042 "Quoted" markup start-string (matched openers & closers) -> no markup:
2043
2044 '*' "*" (*) <*> [*] {*}
2045 ⁅*⁆
2046
2047 Some international quoting styles:
2048 ‘*’ “*” English, ...,
2049 „*“ ‚*‘ »*« ›*‹ German, Czech, ...,
2050 „*” «*» Romanian,
2051 “*„ ‘*‚ Greek,
2052 「*」 『*』traditional Chinese,
2053 ”*” ’*’ »*» ›*› Swedish, Finnish,
2054 „*” ‚*’ Polish,
2055 „*” »*« ’*’ Hungarian,
2056
2057 But this is „*’ emphasized »*‹.
2058 """,
2059 """\
2060 <document source="test data">
2061 <paragraph>
2062 "Quoted" markup start-string (matched openers & closers) -> no markup:
2063 <paragraph>
2064 '*' "*" (*) <*> [*] {*}
2065 ⁅*⁆
2066 <paragraph>
2067 Some international quoting styles:
2068 ‘*’ “*” English, ...,
2069 „*“ ‚*‘ »*« ›*‹ German, Czech, ...,
2070 „*” «*» Romanian,
2071 “*„ ‘*‚ Greek,
2072 「*」 『*』traditional Chinese,
2073 ”*” ’*’ »*» ›*› Swedish, Finnish,
2074 „*” ‚*’ Polish,
2075 „*” »*« ’*’ Hungarian,
2076 <paragraph>
2077 But this is „
2078 <emphasis>
2079 ’ emphasized »
2080 ‹.
2081 """],
2082 ]
2083
2084
2085 if __name__ == '__main__':
2086 unittest.main()