1"""
2    html2textile unittest
3    ~~~~~~~~~~~~~~~~~~~~~
4
5    Unittests for special cases which only works in the html2textile way.
6
7    Note: This only works fine if there is no problematic whitespace handling.
8
9    :copyleft: 2011 by python-creole team, see AUTHORS for more details.
10    :license: GNU GPL v3 or above, see LICENSE for more details.
11"""
12
13
14import unittest
15
16from creole.shared.unknown_tags import preformat_unknown_nodes
17from creole.tests.utils.base_unittest import BaseCreoleTest
18
19
20class TextileTests(BaseCreoleTest):
21    def test_entities(self):
22        """
23        can't be cross tested, because textile would convert < to &#60; and > to &#62;
24        """
25        self.assert_html2textile(
26            textile_string="""
27                less-than sign: <
28                greater-than sign: >
29            """,
30            html_string="""
31                <p>less-than sign: &lt;<br />
32                greater-than sign: &gt;</p>
33            """,
34            # debug=True
35        )
36
37    def test_preformat_unknown_nodes(self):
38        """
39        Put unknown tags in a <pre> area.
40        """
41        self.assert_html2textile(
42            textile_string="""
43                111 <<pre>><x><</pre>>foo<<pre>></x><</pre>> 222
44                333<<pre>><x foo1="bar1"><</pre>>foobar<<pre>></x><</pre>>444
45
46                555<<pre>><x /><</pre>>666
47            """,
48            html_string="""
49                <p>111 <x>foo</x> 222<br />
50                333<x foo1="bar1">foobar</x>444</p>
51
52                <p>555<x />666</p>
53            """,
54            emitter_kwargs={"unknown_emit": preformat_unknown_nodes}
55        )
56
57    def test_transparent_unknown_nodes(self):
58        """
59        transparent_unknown_nodes is the default unknown_emit:
60
61        Remove all unknown html tags and show only
62        their child nodes' content.
63        """
64        self.assert_html2textile(
65            textile_string="""
66                111 foo 222
67                333foobar444
68
69                555666
70            """,
71            html_string="""
72                <p>111 <x>foo</x> 222<br />
73                333<x foo1="bar1">foobar</x>444</p>
74
75                <p>555<x />666</p>
76            """,
77        )
78
79
80if __name__ == '__main__':
81    unittest.main()
82