source: tests/test_specific.py @ f2fad80

Revision f2fad80, 6.1 KB checked in by Aurélien Bompard <aurelien@…>, 23 months ago (diff)

Add specific rendering code for Elyxer

Exlyxer <http://elyxer.nongnu.org/> is a LyX to HTML converter. This
commit adapts to its use of div tags instead of p tags.

Thanks to Denis Prost for reporting.

  • Property mode set to 100644
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4import unittest
5from lxml import etree
6from . import xhtml2odt
7
8class SpecificTrac(unittest.TestCase):
9
10    def test_underline(self):
11        html = '<html xmlns="http://www.w3.org/1999/xhtml"><p><span class="underline">Test</span></p></html>'
12        odt = xhtml2odt(html)
13        self.assertEquals(odt, """<text:p text:style-name="Text_20_body">
14  <text:span text:style-name="underline">Test</text:span>
15</text:p>""")
16
17    def test_underline_outside_p(self):
18        html = '<html xmlns="http://www.w3.org/1999/xhtml"><span class="underline">Test</span></html>'
19        odt = xhtml2odt(html)
20        self.assertEquals(odt, "")
21
22
23class SpecificPygments(unittest.TestCase):
24
25    def _test_mapping(self, css, odtstyle):
26        html = '<html xmlns="http://www.w3.org/1999/xhtml"><div class="code"><pre><span class="%s">Test</span></pre></div></html>' % css
27        odt = xhtml2odt(html)
28        self.assertEquals(odt, """<text:p text:style-name="Source_20_Code">
29  <text:span text:style-name="%s">Test</text:span>
30</text:p><text:p text:style-name="Text_20_body"/>""" % odtstyle)
31
32    def test_highlight_k(self):
33        self._test_mapping("k", "strong")
34
35    def test_highlight_kn(self):
36        self._test_mapping("kn", "strong")
37
38    def test_highlight_nc(self):
39        self._test_mapping("nc", "syntax-highlight.class")
40
41    def test_highlight_nf(self):
42        self._test_mapping("nf", "syntax-highlight.function")
43
44    def test_highlight_nt(self):
45        self._test_mapping("nt", "syntax-highlight.tag")
46
47    def test_highlight_na(self):
48        self._test_mapping("na", "syntax-highlight.attr")
49
50    def test_highlight_nb(self):
51        self._test_mapping("nb", "syntax-highlight.builtin")
52
53    def test_highlight_nn(self):
54        self._test_mapping("nn", "syntax-highlight.namespace")
55
56    def test_highlight_ne(self):
57        self._test_mapping("ne", "syntax-highlight.exception")
58
59    def test_highlight_nv(self):
60        self._test_mapping("nv", "syntax-highlight.var")
61
62    def test_highlight_bp(self):
63        self._test_mapping("bp", "syntax-highlight.builtin.pseudo")
64
65    def test_highlight_s(self):
66        self._test_mapping("s", "syntax-highlight.string")
67
68    def test_highlight_sd(self):
69        self._test_mapping("sd", "syntax-highlight.string")
70
71    def test_highlight_si(self):
72        self._test_mapping("si", "syntax-highlight.string")
73
74    def test_highlight_se(self):
75        self._test_mapping("se", "syntax-highlight.string")
76
77    def test_highlight_sb(self):
78        self._test_mapping("sb", "syntax-highlight.string")
79
80    def test_highlight_s2(self):
81        self._test_mapping("s2", "syntax-highlight.string")
82
83    def test_highlight_mi(self):
84        self._test_mapping("mi", "syntax-highlight.number")
85
86    def test_highlight_mf(self):
87        self._test_mapping("mf", "syntax-highlight.number")
88
89    def test_highlight_o(self):
90        self._test_mapping("o", "strong")
91
92    def test_highlight_ow(self):
93        self._test_mapping("ow", "strong")
94
95    def test_highlight_p(self):
96        html = '<html xmlns="http://www.w3.org/1999/xhtml"><div class="code"><pre><span class="p">Test</span></pre></div></html>'
97        odt = xhtml2odt(html)
98        self.assertEquals(odt, """<text:p text:style-name="Source_20_Code">Test</text:p>"""
99                               """<text:p text:style-name="Text_20_body"/>""")
100
101    def test_highlight_c(self):
102        self._test_mapping("c", "syntax-highlight.comment")
103
104    def test_highlight_err(self):
105        self._test_mapping("err", "syntax-highlight.error")
106
107
108class SpecificElyxer(unittest.TestCase):
109
110    def test_div_standard(self):
111        html = ('<html xmlns="http://www.w3.org/1999/xhtml">'
112                '<div id="globalWrapper">'
113                '<div class="Standard">Test</div>'
114                '</div></html>')
115        odt = xhtml2odt(html)
116        self.assertEquals(odt,
117                '<text:p text:style-name="Text_20_body">Test</text:p>')
118
119    def test_div_addsec(self):
120        html = ('<html xmlns="http://www.w3.org/1999/xhtml">'
121                '<div id="globalWrapper">'
122                '<div class="Addsec">Test</div>'
123                '</div></html>')
124        odt = xhtml2odt(html)
125        self.assertEquals(odt,
126                '<text:p text:style-name="Text_20_body">Test</text:p>')
127
128    def test_div_description(self):
129        html = ('<html xmlns="http://www.w3.org/1999/xhtml">'
130                '<div id="globalWrapper">'
131                '<div class="Description">Test</div>'
132                '</div></html>')
133        odt = xhtml2odt(html)
134        self.assertEquals(odt,
135                '<text:p text:style-name="Text_20_body">Test</text:p>')
136
137    def test_div_subject(self):
138        html = ('<html xmlns="http://www.w3.org/1999/xhtml">'
139                '<div id="globalWrapper">'
140                '<div class="Subject">Test</div>'
141                '</div></html>')
142        odt = xhtml2odt(html)
143        self.assertEquals(odt,
144                '<text:p text:style-name="Title">Test</text:p>')
145
146    def test_div_subtitle(self):
147        html = ('<html xmlns="http://www.w3.org/1999/xhtml">'
148                '<div id="globalWrapper">'
149                '<div class="Subtitle">Test</div>'
150                '</div></html>')
151        odt = xhtml2odt(html)
152        self.assertEquals(odt,
153                '<text:p text:style-name="Subtitle">Test</text:p>')
154
155    def test_footnote(self):
156        html = ('<html xmlns="http://www.w3.org/1999/xhtml">'
157                '<div id="globalWrapper"><p>Main text'
158                  '<span class="FootOuter">'
159                    '<span class="SupFootMarker"> [A] </span>'
160                    '<span class="HoverFoot">'
161                      '<span class="SupFootMarker"> [A] </span>'
162                      'Note content'
163                    '</span>'
164                  '</span>'
165                '</p></div></html>')
166        odt = xhtml2odt(html)
167        self.assertEquals(odt, '<text:p text:style-name="Text_20_body">'
168            'Main text<text:note text:note-class="footnote"><text:note-body>'
169            '<text:p text:style-name="Footnote">Note content</text:p>'
170            '</text:note-body></text:note></text:p>')
171
172
173
174if __name__ == '__main__':
175    unittest.main()
Note: See TracBrowser for help on using the repository browser.