From a66ca623d97c73233f14745423fc274a94299ac7 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 26 Apr 2005 03:57:00 +0000 Subject: 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 --- docutils/HISTORY.txt | 5 ++-- docutils/docs/api/publisher.txt | 9 ++++++ docutils/docutils/writers/html4css1.py | 25 ++++++++++------- docutils/test/DocutilsTestSupport.py | 13 +++++++-- docutils/test/test_writers/test_html4css1.py | 42 +++++++++++++++++++--------- 5 files changed, 67 insertions(+), 27 deletions(-) (limited to 'docutils') 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 ```` content, less the ```` and ```` tags themselves. +html_head + ``parts['html_head']`` contains the HTML ```` content, less + the stylesheet link and the ```` and ```` 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 ``

`` & ``

`` 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 = ('\n\n') + head_prefix_template = ('\n\n') content_type = ('\n') generator = (' -""" % docutils.__version__ +""" + standard_meta_value = standard_meta_value_template % docutils.__version__ standard_stylesheet_value = ('\n') + standard_html_prolog = """\ + + +""" 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': '''

Simple String

\\n''', 'html_body': '''

Simple String

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ Simple String with *markup* @@ -41,7 +42,8 @@ Simple String with *markup* {'fragment': '''

Simple String with markup

\\n''', 'html_body': '''

Simple String with markup

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ Simple String with an even simpler ``inline literal`` @@ -50,7 +52,8 @@ Simple String with an even simpler ``inline literal`` {'fragment': '''

Simple String with an even simpler inline literal

\\n''', 'html_body': '''

Simple String with an even simpler inline literal

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ A simple `anonymous reference`__ @@ -61,7 +64,8 @@ __ http://www.test.com/test_url {'fragment': '''

A simple anonymous reference

\\n''', 'html_body': '''

A simple anonymous reference

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ One paragraph. @@ -74,7 +78,8 @@ Two paragraphs. 'html_body': '''

One paragraph.

Two paragraphs.

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ A simple `named reference`_ with stuff in between the @@ -88,7 +93,8 @@ reference and the target.

\\n''', 'html_body': '''

A simple named reference with stuff in between the reference and the target.

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ +++++ @@ -133,6 +139,7 @@ And even more stuff \\n''', + 'html_head': '''...Title\\n''', 'html_subtitle': '''

Subtitle

\\n''', 'html_title': '''

Title

\\n''', 'subtitle': '''Subtitle''', @@ -169,6 +176,8 @@ Some stuff

Some stuff

\\n''', + 'html_head': '''...Title +\\n''', 'html_title': '''

Title

\\n''', 'meta': '''\\n''', 'title': '''Title'''} @@ -183,7 +192,8 @@ Simple String {'fragment': '''

Simple String

\\n''', 'html_body': '''

Simple String

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ Simple String with *markup* @@ -192,7 +202,8 @@ Simple String with *markup* {'fragment': '''

Simple String with markup

\\n''', 'html_body': '''

Simple String with markup

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ Simple String with an even simpler ``inline literal`` @@ -201,7 +212,8 @@ Simple String with an even simpler ``inline literal`` {'fragment': '''

Simple String with an even simpler inline literal

\\n''', 'html_body': '''

Simple String with an even simpler inline literal

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ A simple `anonymous reference`__ @@ -212,7 +224,8 @@ __ http://www.test.com/test_url {'fragment': '''

A simple anonymous reference

\\n''', 'html_body': '''

A simple anonymous reference

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ A simple `named reference`_ with stuff in between the @@ -226,7 +239,8 @@ reference and the target.

\\n''', 'html_body': '''

A simple named reference with stuff in between the reference and the target.

-
\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ +++++ @@ -280,7 +294,8 @@ And even more stuff -\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ["""\ * bullet @@ -296,7 +311,8 @@ And even more stuff
  • bullet
  • list
  • -\\n'''} +\\n''', + 'html_head': '''...\\n'''} """], ]) -- cgit v1.2.1