add project gutenberg
[docutils.git] / test / test_writers / test_html4css1_misc.py
blob684894619e459c528a28e5496bccb506643d85e1
1 #! /usr/bin/env python
2 # coding: utf-8
4 # $Id$
5 # Authors: Lea Wiemann, Dmitry Shachnev, Günter Milde
6 # Maintainer: docutils-develop@lists.sourceforge.net
7 # Copyright: This module has been placed in the public domain.
9 """
10 Miscellaneous HTML writer tests.
11 """
13 from __init__ import DocutilsTestSupport
14 from docutils import core
15 from docutils._compat import b
17 class EncodingTestCase(DocutilsTestSupport.StandardTestCase):
19 def test_xmlcharrefreplace(self):
20 # Test that xmlcharrefreplace is the default output encoding
21 # error handler.
22 settings_overrides={
23 'output_encoding': 'latin1',
24 'stylesheet': '',
25 '_disable_config': True,}
26 result = core.publish_string(
27 u'EUR = \u20ac', writer_name='html4css1',
28 settings_overrides=settings_overrides)
29 # Encoding a euro sign with latin1 doesn't work, so the
30 # xmlcharrefreplace handler is used.
31 self.assertIn(b('EUR = €'), result)
33 class SettingsTestCase(DocutilsTestSupport.StandardTestCase):
34 data = 'test'
36 def test_default_stylesheet(self):
37 # default style sheet, embedded
38 mysettings = {'_disable_config': True,}
39 styles = core.publish_parts(self.data, writer_name='html4css1',
40 settings_overrides=mysettings)['stylesheet']
41 self.assertIn('Default cascading style sheet '
42 'for the HTML output of Docutils.', styles)
44 def test_default_stylesheet_linked(self):
45 # default style sheet, linked
46 mysettings = {'_disable_config': True,
47 'embed_stylesheet': False}
48 styles = core.publish_parts(self.data, writer_name='html4css1',
49 settings_overrides=mysettings)['stylesheet']
50 self.assertIn('docutils/writers/html4css1/html4css1.css', styles)
52 def test_math_stylesheet_linked(self):
53 # default + math style sheet, linked
54 mysettings = {'_disable_config': True,
55 'embed_stylesheet': False,
56 'stylesheet_path': 'html4css1.css, math.css'}
57 styles = core.publish_parts(self.data, writer_name='html4css1',
58 settings_overrides=mysettings)['stylesheet']
59 self.assertIn('docutils/writers/html4css1/html4css1.css', styles)
60 self.assertIn('docutils/writers/html4css1/math.css', styles)
62 def test_custom_stylesheet_linked(self):
63 # default + custom style sheet, linked
64 mysettings = {'_disable_config': True,
65 'embed_stylesheet': False,
66 'stylesheet_path': 'html4css1.css, '
67 'data/ham.css'}
68 styles = core.publish_parts(self.data, writer_name='html4css1',
69 settings_overrides=mysettings)['stylesheet']
70 self.assertIn('docutils/writers/html4css1/html4css1.css', styles)
71 self.assertIn('href="data/ham.css"', styles)
73 def test_custom_stylesheet_dir(self):
74 mysettings = {'_disable_config': True,
75 'embed_stylesheet': False,
76 'stylesheet_dirs': ('../docutils/writers/html4css1/',
77 'data'),
78 'stylesheet_path': 'html4css1.css, ham.css'}
79 styles = core.publish_parts(self.data, writer_name='html4css1',
80 settings_overrides=mysettings)['stylesheet']
81 self.assertIn('docutils/writers/html4css1/html4css1.css', styles)
82 self.assertIn('href="data/ham.css"', styles)
84 def test_custom_stylesheet_dir_embedded(self):
85 mysettings = {'_disable_config': True,
86 'embed_stylesheet': True,
87 'stylesheet_dirs': ('../docutils/writers/html4css1/',
88 'data'),
89 'stylesheet_path': 'ham.css'}
90 styles = core.publish_parts(self.data, writer_name='html4css1',
91 settings_overrides=mysettings)['stylesheet']
92 self.assertIn('dl.docutils dd {\n margin-bottom: 0.5em }', styles)
94 class MathTestCase(DocutilsTestSupport.StandardTestCase):
96 """Attention: This class tests the current implementation of maths support
97 which is open to change in future Docutils releases. """
99 mathjax_script = '<script type="text/javascript" src="%s">'
100 default_mathjax_url = ('http://cdn.mathjax.org/mathjax/latest/MathJax.js'
101 '?config=TeX-AMS-MML_HTMLorMML')
102 custom_mathjax_url = ('file:///usr/share/javascript/mathjax/MathJax.js'
103 '?config=TeX-AMS-MML_HTMLorMML')
104 data = ':math:`42`'
106 def test_math_output_default(self):
107 # HTML with math.css stylesheet (since 0.11)
108 mysettings = {'_disable_config': True,}
109 styles = core.publish_parts(self.data, writer_name='html4css1',
110 settings_overrides=mysettings)['stylesheet']
111 self.assertIn('convert LaTeX equations to HTML output.', styles)
113 def test_math_output_mathjax(self):
114 # Explicitly specifying math_output=MathJax, case insensitively
115 # use default MathJax URL
116 mysettings = {'_disable_config': True,
117 'math_output': 'MathJax'}
118 head = core.publish_parts(self.data, writer_name='html4css1',
119 settings_overrides=mysettings)['head']
120 self.assertIn(self.mathjax_script % self.default_mathjax_url, head)
122 def test_math_output_mathjax_custom(self):
123 # Customizing MathJax URL
124 mysettings = {'_disable_config': True,
125 'math_output':
126 'mathjax %s' % self.custom_mathjax_url}
127 head = core.publish_parts(self.data, writer_name='html4css1',
128 settings_overrides=mysettings)['head']
129 self.assertIn(self.mathjax_script % self.custom_mathjax_url, head)
131 def test_math_output_html(self):
132 mysettings = {'_disable_config': True,
133 'math_output': 'HTML'}
134 head = core.publish_parts(self.data, writer_name='html4css1',
135 settings_overrides=mysettings)['head']
136 # There should be no MathJax script when math_output is not MathJax
137 self.assertNotIn('MathJax.js', head)
139 def test_math_output_html_stylesheet(self):
140 mysettings = {'_disable_config': True,
141 'math_output': 'HTML math.css,custom/style.css',
142 'stylesheet_dirs': ('.', 'functional/input/data'),
143 'embed_stylesheet': False}
144 styles = core.publish_parts(self.data, writer_name='html4css1',
145 settings_overrides=mysettings)['stylesheet']
146 self.assertEqual(u"""\
147 <link rel="stylesheet" href="functional/input/data/html4css1.css" type="text/css" />
148 <link rel="stylesheet" href="functional/input/data/math.css" type="text/css" />
149 <link rel="stylesheet" href="custom/style.css" type="text/css" />
150 """, styles)
152 def test_math_output_mathjax_no_math(self):
153 mysettings = {'_disable_config': True,
154 'math_output': 'MathJax'}
155 # There should be no math script when text does not contain math
156 head = core.publish_parts('No math.', writer_name='html4css1')['head']
157 self.assertNotIn('MathJax', head)
160 if __name__ == '__main__':
161 import unittest
162 unittest.main()