diff options
| author | goodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2005-04-26 03:57:00 +0000 |
|---|---|---|
| committer | goodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2005-04-26 03:57:00 +0000 |
| commit | a66ca623d97c73233f14745423fc274a94299ac7 (patch) | |
| tree | 94e0a4d716826f7c282e001526f5ba3c0ad7de37 /docutils | |
| parent | b66f96780587f6cdf04168b76780b805d79c7369 (diff) | |
| download | docutils-a66ca623d97c73233f14745423fc274a94299ac7.tar.gz | |
Added ``html_prolog`` & ``html_head`` to HTML writer parts dictionary exposed by ``docutils.core.publish_parts``; updated tests & docs. At the request of Marcelo Huerta.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@3257 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
| -rw-r--r-- | docutils/HISTORY.txt | 5 | ||||
| -rw-r--r-- | docutils/docs/api/publisher.txt | 9 | ||||
| -rw-r--r-- | docutils/docutils/writers/html4css1.py | 25 | ||||
| -rw-r--r-- | docutils/test/DocutilsTestSupport.py | 13 | ||||
| -rwxr-xr-x | docutils/test/test_writers/test_html4css1.py | 42 |
5 files changed, 67 insertions, 27 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 9fa7e30d6..66a611350 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -140,8 +140,9 @@ Changes Since 0.3.7 - Added support for table stub columns. - Added support for ``align`` attribute on ``figure`` elements. - Added the ``cloak_email_addresses`` setting & support. - - Added ``html_body``, ``html_title``, & ``html_subtitle`` to parts - dictionary exposed by ``docutils.core.publish_parts``. + - Added ``html_prolog``, ``html_head``, ``html_body``, + ``html_title``, & ``html_subtitle`` to parts dictionary exposed by + ``docutils.core.publish_parts``. * docutils/writers/latex2e.py: diff --git a/docutils/docs/api/publisher.txt b/docutils/docs/api/publisher.txt index 5d793f003..55883f1ae 100644 --- a/docutils/docs/api/publisher.txt +++ b/docutils/docs/api/publisher.txt @@ -129,6 +129,15 @@ html_body ``parts['html_body']`` contains the HTML ``<body>`` content, less the ``<body>`` and ``</body>`` tags themselves. +html_head + ``parts['html_head']`` contains the HTML ``<head>`` content, less + the stylesheet link and the ``<head>`` and ``</head>`` tags + themselves. + +html_prolog + ``parts['html_prolog]`` contains the XML declaration and the + doctype declaration. + html_subtitle ``parts['html_subtitle']`` contains the document subtitle, including the enclosing ``<h2 class="subtitle">`` & ``</h2>`` diff --git a/docutils/docutils/writers/html4css1.py b/docutils/docutils/writers/html4css1.py index 691ebb4ec..76499dea6 100644 --- a/docutils/docutils/writers/html4css1.py +++ b/docutils/docutils/writers/html4css1.py @@ -131,7 +131,8 @@ class Writer(writers.Writer): writers.Writer.assemble_parts(self) for part in ('title', 'subtitle', 'docinfo', 'body', 'header', 'footer', 'meta', 'stylesheet', 'fragment', - 'html_title', 'html_subtitle', 'html_body'): + 'html_prolog', 'html_head', 'html_title', 'html_subtitle', + 'html_body'): self.parts[part] = ''.join(getattr(self.visitor, part)) @@ -183,8 +184,8 @@ class HTMLTranslator(nodes.NodeVisitor): ' PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' ' "http://www.w3.org/TR/xhtml1/DTD/' 'xhtml1-transitional.dtd">\n') - html_head = ('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="%s" ' - 'lang="%s">\n<head>\n') + head_prefix_template = ('<html xmlns="http://www.w3.org/1999/xhtml"' + ' xml:lang="%s" lang="%s">\n<head>\n') content_type = ('<meta http-equiv="Content-Type" content="text/html; ' 'charset=%s" />\n') generator = ('<meta name="generator" content="Docutils %s: ' @@ -201,14 +202,16 @@ class HTMLTranslator(nodes.NodeVisitor): self.language = languages.get_language(lcode) self.meta = [self.content_type % settings.output_encoding, self.generator % docutils.__version__] - self.head_prefix = [ - self.doctype, - self.html_head % (lcode, lcode)] - self.head_prefix.extend(self.meta) + self.head_prefix = [] + self.html_prolog = [] if settings.xml_declaration: - self.head_prefix.insert(0, self.xml_declaration + self.head_prefix.append(self.xml_declaration % settings.output_encoding) - self.head = [] + self.html_prolog.append(self.xml_declaration) # not interpolated + self.head_prefix.extend([self.doctype, + self.head_prefix_template % (lcode, lcode)]) + self.html_prolog.append(self.doctype) + self.head = self.meta[:] if settings.embed_stylesheet: stylesheet = utils.get_stylesheet_reference(settings, os.path.join(os.getcwd(), 'dummy')) @@ -245,6 +248,7 @@ class HTMLTranslator(nodes.NodeVisitor): self.subtitle = [] self.header = [] self.footer = [] + self.html_head = [] self.html_title = [] self.html_subtitle = [] self.html_body = [] @@ -621,12 +625,13 @@ class HTMLTranslator(nodes.NodeVisitor): # empty or untitled document? if not len(node) or not isinstance(node[0], nodes.title): # for XHTML conformance, modulo IE6 appeasement: - self.head.insert(0, '<title></title>\n') + self.head.append('<title></title>\n') def depart_document(self, node): self.fragment.extend(self.body) self.body_prefix.append(self.starttag(node, 'div', CLASS='document')) self.body_suffix.insert(0, '</div>\n') + self.html_head.extend(self.head) self.html_body.extend(self.body_prefix[1:] + self.body_pre_docinfo + self.docinfo + self.body + self.body_suffix[:-1]) diff --git a/docutils/test/DocutilsTestSupport.py b/docutils/test/DocutilsTestSupport.py index 40ac89c4f..87a200598 100644 --- a/docutils/test/DocutilsTestSupport.py +++ b/docutils/test/DocutilsTestSupport.py @@ -731,12 +731,17 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): expected = self.expected % {'version': docutils.__version__} self.compare_output(self.input, output, expected) - standard_meta_value = """\ + standard_meta_value_template = """\ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="Docutils %s: http://docutils.sourceforge.net/" /> -""" % docutils.__version__ +""" + standard_meta_value = standard_meta_value_template % docutils.__version__ standard_stylesheet_value = ('<link rel="stylesheet" href="default.css" ' 'type="text/css" />\n') + standard_html_prolog = """\ +<?xml version="1.0" encoding="%s" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +""" def format_output(self, parts): """Minimize & standardize the output.""" @@ -748,6 +753,10 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): parts['meta'] = parts['meta'].replace(self.standard_meta_value, '') if parts['stylesheet'] == self.standard_stylesheet_value: del parts['stylesheet'] + parts['html_head'] = parts['html_head'].replace( + self.standard_meta_value, '...') + parts['html_prolog'] = parts['html_prolog'].replace( + self.standard_html_prolog, '') # remove empty values: for key in parts.keys(): if not parts[key]: diff --git a/docutils/test/test_writers/test_html4css1.py b/docutils/test/test_writers/test_html4css1.py index d93997a2d..70d3be772 100755 --- a/docutils/test/test_writers/test_html4css1.py +++ b/docutils/test/test_writers/test_html4css1.py @@ -32,7 +32,8 @@ Simple String {'fragment': '''<p>Simple String</p>\\n''', 'html_body': '''<div class="document"> <p>Simple String</p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ Simple String with *markup* @@ -41,7 +42,8 @@ Simple String with *markup* {'fragment': '''<p>Simple String with <em>markup</em></p>\\n''', 'html_body': '''<div class="document"> <p>Simple String with <em>markup</em></p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ Simple String with an even simpler ``inline literal`` @@ -50,7 +52,8 @@ Simple String with an even simpler ``inline literal`` {'fragment': '''<p>Simple String with an even simpler <tt class="docutils literal"><span class="pre">inline</span> <span class="pre">literal</span></tt></p>\\n''', 'html_body': '''<div class="document"> <p>Simple String with an even simpler <tt class="docutils literal"><span class="pre">inline</span> <span class="pre">literal</span></tt></p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ A simple `anonymous reference`__ @@ -61,7 +64,8 @@ __ http://www.test.com/test_url {'fragment': '''<p>A simple <a class="reference" href="http://www.test.com/test_url">anonymous reference</a></p>\\n''', 'html_body': '''<div class="document"> <p>A simple <a class="reference" href="http://www.test.com/test_url">anonymous reference</a></p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ One paragraph. @@ -74,7 +78,8 @@ Two paragraphs. 'html_body': '''<div class="document"> <p>One paragraph.</p> <p>Two paragraphs.</p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ A simple `named reference`_ with stuff in between the @@ -88,7 +93,8 @@ reference and the target.</p>\\n''', 'html_body': '''<div class="document"> <p>A simple <a class="reference" href="http://www.test.com/test_url">named reference</a> with stuff in between the reference and the target.</p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ +++++ @@ -133,6 +139,7 @@ And even more stuff </div> </div> </div>\\n''', + 'html_head': '''...<title>Title</title>\\n''', 'html_subtitle': '''<h2 class="subtitle" id="subtitle">Subtitle</h2>\\n''', 'html_title': '''<h1 class="title">Title</h1>\\n''', 'subtitle': '''Subtitle''', @@ -169,6 +176,8 @@ Some stuff </table> <p>Some stuff</p> </div>\\n''', + 'html_head': '''...<title>Title</title> +<meta name="author" content="me" />\\n''', 'html_title': '''<h1 class="title">Title</h1>\\n''', 'meta': '''<meta name="author" content="me" />\\n''', 'title': '''Title'''} @@ -183,7 +192,8 @@ Simple String {'fragment': '''<p>Simple String</p>\\n''', 'html_body': '''<div class="document"> <p>Simple String</p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ Simple String with *markup* @@ -192,7 +202,8 @@ Simple String with *markup* {'fragment': '''<p>Simple String with <em>markup</em></p>\\n''', 'html_body': '''<div class="document"> <p>Simple String with <em>markup</em></p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ Simple String with an even simpler ``inline literal`` @@ -201,7 +212,8 @@ Simple String with an even simpler ``inline literal`` {'fragment': '''<p>Simple String with an even simpler <tt class="docutils literal"><span class="pre">inline</span> <span class="pre">literal</span></tt></p>\\n''', 'html_body': '''<div class="document"> <p>Simple String with an even simpler <tt class="docutils literal"><span class="pre">inline</span> <span class="pre">literal</span></tt></p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ A simple `anonymous reference`__ @@ -212,7 +224,8 @@ __ http://www.test.com/test_url {'fragment': '''<p>A simple <a class="reference" href="http://www.test.com/test_url">anonymous reference</a></p>\\n''', 'html_body': '''<div class="document"> <p>A simple <a class="reference" href="http://www.test.com/test_url">anonymous reference</a></p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ A simple `named reference`_ with stuff in between the @@ -226,7 +239,8 @@ reference and the target.</p>\\n''', 'html_body': '''<div class="document"> <p>A simple <a class="reference" href="http://www.test.com/test_url">named reference</a> with stuff in between the reference and the target.</p> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ +++++ @@ -280,7 +294,8 @@ And even more stuff </div> </div> </div> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ["""\ * bullet @@ -296,7 +311,8 @@ And even more stuff <li>bullet</li> <li>list</li> </ul> -</div>\\n'''} +</div>\\n''', + 'html_head': '''...<title></title>\\n'''} """], ]) |
