diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-11-13 16:15:23 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2022-11-13 16:15:23 +0000 |
| commit | 4a8b25042a2f1ddd499ff2df339613809ce96ac0 (patch) | |
| tree | 242cbd9b7f6af6796fc41d5e4272f450d4ecac86 | |
| parent | 456cd24b162f3ad2cf622fc059ff1aa2f49e9d30 (diff) | |
| download | docutils-4a8b25042a2f1ddd499ff2df339613809ce96ac0.tar.gz | |
Refactor HTMLTranslator initialization and parts setup.
Use utils.xml_declaration().
Don't write charset (encoding) declaration if the intended output encoding
is not known.
Copy "meta" part content into "head" in `depart_document()`
(i.e. after collecting all items).
Obsoletes auxiliary method `add_meta()`. Remove it.
Changes to the HTML output (no space character before closing tag of XML
declaration, order of metadata elements) don't affect the HTML semantics,
styling, and rendering.
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9240 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
28 files changed, 127 insertions, 142 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 5ce6f387b..d7136a264 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -51,6 +51,15 @@ Changes Since 0.19 * docutils/docutils/utils/__init__.py - New utility function `xml_declaration()`. + +* docutils/docutils/writers/_html_base.py + + - Refactoring of HTMLTranslator initialization and collecting of + document "parts". Adapt HTML writers importing `_html_base`. + + Changes to the HTML output (no space character before closing tag of + XML declaration, order of metadata elements) + don't affect the HTML semantics, styling, and rendering. * docutils/writers/latex2e/__init__.py diff --git a/docutils/docutils/writers/_html_base.py b/docutils/docutils/writers/_html_base.py index 097b04be8..1f3f38eb2 100644 --- a/docutils/docutils/writers/_html_base.py +++ b/docutils/docutils/writers/_html_base.py @@ -233,15 +233,15 @@ class HTMLTranslator(nodes.NodeVisitor): This way, changes in stack use will not bite you. """ - xml_declaration = '<?xml version="1.0" encoding="%s" ?>\n' doctype = '<!DOCTYPE html>\n' doctype_mathml = doctype head_prefix_template = ('<html xmlns="http://www.w3.org/1999/xhtml"' ' xml:lang="%(lang)s" lang="%(lang)s">\n<head>\n') content_type = '<meta charset="%s" />\n' - generator = ('<meta name="generator" content="Docutils %s: ' - 'https://docutils.sourceforge.io/" />\n') + generator = ( + f'<meta name="generator" content="Docutils {docutils.__version__}: ' + 'https://docutils.sourceforge.io/" />\n') # Template for the MathJax script in the header: mathjax_script = '<script type="text/javascript" src="%s"></script>\n' @@ -278,32 +278,12 @@ class HTMLTranslator(nodes.NodeVisitor): def __init__(self, document): nodes.NodeVisitor.__init__(self, document) + # process settings self.settings = settings = document.settings - lcode = settings.language_code - self.language = languages.get_language(lcode, document.reporter) - self.meta = [self.generator % docutils.__version__] - self.head_prefix = [] - self.html_prolog = [] - if settings.xml_declaration: - self.head_prefix.append(self.xml_declaration - % _encoding(settings)) - # self.content_type = "" - # encoding not interpolated: - self.html_prolog.append(self.xml_declaration) - self.head = self.meta[:] - self.stylesheet = [self.stylesheet_call(path) - for path in utils.get_stylesheet_list(settings)] - self.body_prefix = ['</head>\n<body>\n'] - # document title, subtitle display - self.body_pre_docinfo = [] - # author, date, etc. - self.docinfo = [] - self.body = [] - self.fragment = [] - self.body_suffix = ['</body>\n</html>\n'] - self.section_level = 0 + self.language = languages.get_language( + settings.language_code, document.reporter) self.initial_header_level = int(settings.initial_header_level) - # image_loading only defined for HTML5 writer + # image_loading (only defined for HTML5 writer) self.image_loading = getattr(settings, 'image_loading', None) # legacy setting embed_images: if getattr(settings, 'embed_images', None) is True: @@ -324,26 +304,52 @@ class HTMLTranslator(nodes.NodeVisitor): self.math_output_options = self.math_output[1:] self.math_output = self.math_output[0].lower() + # set up "parts" (cf. docs/api/publisher.html#publish-parts-details) + # + self.body = [] # equivalent to `fragment`, ≠ `html_body` + self.body_prefix = ['</head>\n<body>\n'] # + optional header + self.body_pre_docinfo = [] # document heading (title and subtitle) + self.body_suffix = ['</body>\n</html>\n'] # + optional footer + self.docinfo = [] + self.footer = [] + self.fragment = [] # main content of the document ("naked" body) + self.head = [] + self.head_prefix = [] # everything up to and including <head> + self.header = [] + self.html_body = [] + self.html_head = [self.content_type] # charset not interpolated + self.html_prolog = [] + self.html_subtitle = [] + self.html_title = [] + self.meta = [self.generator] + self.stylesheet = [self.stylesheet_call(path) + for path in utils.get_stylesheet_list(settings)] + self.title = [] + self.subtitle = [] + if settings.xml_declaration: + self.head_prefix.append( + utils.xml_declaration(settings.output_encoding)) + self.html_prolog.append( + utils.xml_declaration('%s')) # encoding not interpolated + if (settings.output_encoding + and settings.output_encoding.lower() != 'unicode'): + self.meta.insert(0, self.content_type % settings.output_encoding) + + # bookkeeping attributes; reflect state of translator + # self.context = [] """Heterogeneous stack. Used by visit_* and depart_* functions in conjunction with the tree - traversal. Make sure that the pops correspond to the pushes.""" - + traversal. Make sure that the pops correspond to the pushes. + """ + self.section_level = 0 self.colspecs = [] self.compact_p = True self.compact_simple = False self.compact_field_list = False self.in_docinfo = False self.in_sidebar = False - self.title = [] - self.subtitle = [] - self.header = [] - self.footer = [] - self.html_head = [self.content_type] # charset not interpolated - self.html_title = [] - self.html_subtitle = [] - self.html_body = [] self.in_document_title = 0 # len(self.body) or 0 self.in_mailto = False self.author_in_authors = False # for html4css1 @@ -784,12 +790,10 @@ class HTMLTranslator(nodes.NodeVisitor): def visit_docinfo_item(self, node, name, meta=True): if meta: - meta_tag = '<meta name="%s" content="%s" />\n' \ - % (name, self.attval(node.astext())) - self.add_meta(meta_tag) - self.body.append( - '<dt class="%s">%s<span class="colon">:</span></dt>\n' - % (name, self.language.labels[name])) + self.meta.append(f'<meta name="{name}" ' + f'content="{self.attval(node.astext())}" />\n') + self.body.append(f'<dt class="{name}">{self.language.labels[name]}' + '<span class="colon">:</span></dt>\n') self.body.append(self.starttag(node, 'dd', '', CLASS=name)) def depart_docinfo_item(self): @@ -812,11 +816,10 @@ class HTMLTranslator(nodes.NodeVisitor): self.head_prefix_template % {'lang': self.settings.language_code}]) self.html_prolog.append(self.doctype) - self.meta.insert(0, self.content_type % _encoding(self.settings)) - self.head.insert(0, self.content_type % _encoding(self.settings)) + self.head = self.meta[:] + self.head if 'name="dcterms.' in ''.join(self.meta): self.head.append('<link rel="schema.dcterms"' - 'href="http://purl.org/dc/terms/"/>') + ' href="http://purl.org/dc/terms/"/>') if self.math_header: if self.math_output == 'mathjax': self.head.extend(self.math_header) @@ -1311,16 +1314,12 @@ class HTMLTranslator(nodes.NodeVisitor): # Meta tags: 'lang' attribute replaced by 'xml:lang' in XHTML 1.1 # HTML5/polyglot recommends using both def visit_meta(self, node): - meta = self.emptytag(node, 'meta', **node.non_default_attributes()) - self.add_meta(meta) + self.meta.append(self.emptytag(node, 'meta', + **node.non_default_attributes())) def depart_meta(self, node): pass - def add_meta(self, tag): - self.meta.append(tag) - self.head.append(tag) - def visit_option(self, node): self.body.append(self.starttag(node, 'span', '', CLASS='option')) @@ -1783,10 +1782,3 @@ class SimpleListChecker(nodes.GenericNodeVisitor): visit_substitution_definition = ignore_node visit_target = ignore_node visit_pending = ignore_node - - -def _encoding(settings): - """TEMPORARY, remove in Docutils 0.21""" - if settings.output_encoding == 'unicode': - return 'utf-8' - return settings.output_encoding diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py index a3526e074..1f1ec7c63 100644 --- a/docutils/docutils/writers/html4css1/__init__.py +++ b/docutils/docutils/writers/html4css1/__init__.py @@ -344,7 +344,7 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): if meta: meta_tag = '<meta name="%s" content="%s" />\n' \ % (name, self.attval(node.astext())) - self.add_meta(meta_tag) + self.meta.append(meta_tag) self.body.append(self.starttag(node, 'tr', '')) self.body.append('<th class="docinfo-name">%s:</th>\n<td>' % self.language.labels[name]) diff --git a/docutils/docutils/writers/html5_polyglot/__init__.py b/docutils/docutils/writers/html5_polyglot/__init__.py index 6cba650ff..10d7e2d95 100644 --- a/docutils/docutils/writers/html5_polyglot/__init__.py +++ b/docutils/docutils/writers/html5_polyglot/__init__.py @@ -138,8 +138,8 @@ class HTMLTranslator(_html_base.HTMLTranslator): def visit_authors(self, node): self.visit_docinfo_item(node, 'authors', meta=False) for subnode in node: - self.add_meta('<meta name="author" content="%s" />\n' % - self.attval(subnode.astext())) + self.meta.append('<meta name="author" content=' + f'"{self.attval(subnode.astext())}" />\n') def depart_authors(self, node): self.depart_docinfo_item() @@ -178,8 +178,8 @@ class HTMLTranslator(_html_base.HTMLTranslator): # see https://wiki.whatwg.org/wiki/MetaExtensions def visit_copyright(self, node): self.visit_docinfo_item(node, 'copyright', meta=False) - self.add_meta('<meta name="dcterms.rights" content="%s" />\n' - % self.attval(node.astext())) + self.meta.append('<meta name="dcterms.rights" ' + f'content="{self.attval(node.astext())}" />\n') def depart_copyright(self, node): self.depart_docinfo_item() @@ -187,8 +187,8 @@ class HTMLTranslator(_html_base.HTMLTranslator): # no standard meta tag name in HTML5, use dcterms.date def visit_date(self, node): self.visit_docinfo_item(node, 'date', meta=False) - self.add_meta('<meta name="dcterms.date" content="%s" />\n' - % self.attval(node.astext())) + self.meta.append('<meta name="dcterms.date" ' + f'content="{self.attval(node.astext())}" />\n') def depart_date(self, node): self.depart_docinfo_item() @@ -197,16 +197,14 @@ class HTMLTranslator(_html_base.HTMLTranslator): title = (node.get('title', '') or os.path.basename(node['source']) or 'untitled Docutils document') self.head.append(f'<title>{self.encode(title)}</title>\n') + self.meta.append(self.viewport) def depart_document(self, node): self.head_prefix.extend([self.doctype, self.head_prefix_template % {'lang': self.settings.language_code}]) self.html_prolog.append(self.doctype) - self.meta.insert(0, self.viewport) - self.head.insert(0, self.viewport) - self.meta.insert(0, self.content_type % _encoding(self)) - self.head.insert(0, self.content_type % _encoding(self)) + self.head = self.meta[:] + self.head if 'name="dcterms.' in ''.join(self.meta): self.head.append('<link rel="schema.dcterms"' ' href="http://purl.org/dc/terms/"/>') @@ -384,8 +382,8 @@ class HTMLTranslator(_html_base.HTMLTranslator): def visit_meta(self, node): if node.hasattr('lang'): node['xml:lang'] = node['lang'] - meta = self.emptytag(node, 'meta', **node.non_default_attributes()) - self.add_meta(meta) + self.meta.append(self.emptytag(node, 'meta', + **node.non_default_attributes())) def depart_meta(self, node): pass @@ -452,10 +450,3 @@ class HTMLTranslator(_html_base.HTMLTranslator): f' href="#{ids[0]}"></a>') close_tag = close_tag.replace('</h', self_link + '</h') return start_tag, close_tag - - -def _encoding(self): - """TEMPORARY, remove in Docutils 0.21""" - if self.settings.output_encoding == 'unicode': - return 'utf-8' - return self.settings.output_encoding diff --git a/docutils/docutils/writers/pep_html/template.txt b/docutils/docutils/writers/pep_html/template.txt index 990151d44..e8cd351c6 100644 --- a/docutils/docutils/writers/pep_html/template.txt +++ b/docutils/docutils/writers/pep_html/template.txt @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="%(encoding)s" ?> +<?xml version="1.0" encoding="%(encoding)s"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- diff --git a/docutils/docutils/writers/s5_html/__init__.py b/docutils/docutils/writers/s5_html/__init__.py index 555a5d8ac..2121509c6 100644 --- a/docutils/docutils/writers/s5_html/__init__.py +++ b/docutils/docutils/writers/s5_html/__init__.py @@ -164,7 +164,7 @@ class S5HTMLTranslator(html4css1.HTMLTranslator): 'control_visibility': control_visibility}) if not self.document.settings.current_slide: self.stylesheet.append(self.disable_current_slide) - self.add_meta('<meta name="version" content="S5 1.1" />\n') + self.meta.append('<meta name="version" content="S5 1.1" />\n') self.s5_footer = [] self.s5_header = [] self.section_count = 0 @@ -282,8 +282,7 @@ class S5HTMLTranslator(html4css1.HTMLTranslator): self.head_prefix_template % {'lang': self.settings.language_code}]) self.html_prolog.append(self.doctype) - self.meta.insert(0, self.content_type % _encoding(self)) - self.head.insert(0, self.content_type % _encoding(self)) + self.head = self.meta[:] + self.head if self.math_header: if self.math_output == 'mathjax': self.head.extend(self.math_header) @@ -350,10 +349,3 @@ class S5HTMLTranslator(html4css1.HTMLTranslator): def visit_title(self, node): html4css1.HTMLTranslator.visit_title(self, node) - - -def _encoding(self): - """TEMPORARY, remove in Docutils 0.21""" - if self.settings.output_encoding == 'unicode': - return 'utf-8' - return self.settings.output_encoding diff --git a/docutils/test/functional/expected/compact_lists.html b/docutils/test/functional/expected/compact_lists.html index 9a884c653..b2ee45a25 100644 --- a/docutils/test/functional/expected/compact_lists.html +++ b/docutils/test/functional/expected/compact_lists.html @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> diff --git a/docutils/test/functional/expected/dangerous.html b/docutils/test/functional/expected/dangerous.html index 1d4689bc7..41c108705 100644 --- a/docutils/test/functional/expected/dangerous.html +++ b/docutils/test/functional/expected/dangerous.html @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> diff --git a/docutils/test/functional/expected/embed_images_html5.html b/docutils/test/functional/expected/embed_images_html5.html index ae436afe4..e582eb371 100644 --- a/docutils/test/functional/expected/embed_images_html5.html +++ b/docutils/test/functional/expected/embed_images_html5.html @@ -1,8 +1,8 @@ <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> -<meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1" /> +<meta charset="utf-8"/> <meta name="generator" content="Docutils 0.19.1b.dev: https://docutils.sourceforge.io/" /> <title>Embedded Images</title> <link rel="stylesheet" href="../input/data/minimal.css" type="text/css" /> diff --git a/docutils/test/functional/expected/field_name_limit.html b/docutils/test/functional/expected/field_name_limit.html index b9b382930..019a2c9af 100644 --- a/docutils/test/functional/expected/field_name_limit.html +++ b/docutils/test/functional/expected/field_name_limit.html @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> diff --git a/docutils/test/functional/expected/footnotes_html5.html b/docutils/test/functional/expected/footnotes_html5.html index 733baa90a..4310f7906 100644 --- a/docutils/test/functional/expected/footnotes_html5.html +++ b/docutils/test/functional/expected/footnotes_html5.html @@ -2,8 +2,8 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta charset="utf-8" /> -<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="generator" content="Docutils 0.19.1b.dev: https://docutils.sourceforge.io/" /> +<meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Test footnote and citation rendering</title> <link rel="stylesheet" href="../input/data/minimal.css" type="text/css" /> <link rel="stylesheet" href="../input/data/responsive.css" type="text/css" /> diff --git a/docutils/test/functional/expected/math_output_html.html b/docutils/test/functional/expected/math_output_html.html index 68b9d440b..29011fbbc 100644 --- a/docutils/test/functional/expected/math_output_html.html +++ b/docutils/test/functional/expected/math_output_html.html @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> diff --git a/docutils/test/functional/expected/math_output_latex.html b/docutils/test/functional/expected/math_output_latex.html index 9faab8cab..7a6b94f27 100644 --- a/docutils/test/functional/expected/math_output_latex.html +++ b/docutils/test/functional/expected/math_output_latex.html @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> diff --git a/docutils/test/functional/expected/math_output_mathjax.html b/docutils/test/functional/expected/math_output_mathjax.html index 18b5ace74..a80d610eb 100644 --- a/docutils/test/functional/expected/math_output_mathjax.html +++ b/docutils/test/functional/expected/math_output_mathjax.html @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> diff --git a/docutils/test/functional/expected/math_output_mathml.html b/docutils/test/functional/expected/math_output_mathml.html index 5615b7d55..46deac3fc 100644 --- a/docutils/test/functional/expected/math_output_mathml.html +++ b/docutils/test/functional/expected/math_output_mathml.html @@ -2,8 +2,8 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta charset="utf-8" /> -<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="generator" content="Docutils 0.19.1b.dev: https://docutils.sourceforge.io/" /> +<meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Mathematics</title> <link rel="stylesheet" href="../input/data/minimal.css" type="text/css" /> <link rel="stylesheet" href="../input/data/plain.css" type="text/css" /> diff --git a/docutils/test/functional/expected/misc_rst_html4css1.html b/docutils/test/functional/expected/misc_rst_html4css1.html index 6027bd975..9fec8d866 100644 --- a/docutils/test/functional/expected/misc_rst_html4css1.html +++ b/docutils/test/functional/expected/misc_rst_html4css1.html @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> diff --git a/docutils/test/functional/expected/misc_rst_html5.html b/docutils/test/functional/expected/misc_rst_html5.html index 068014f3e..8b48117d2 100644 --- a/docutils/test/functional/expected/misc_rst_html5.html +++ b/docutils/test/functional/expected/misc_rst_html5.html @@ -2,8 +2,8 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta charset="utf-8" /> -<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="generator" content="Docutils 0.19.1b.dev: https://docutils.sourceforge.io/" /> +<meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Additional tests with HTML 5</title> <link rel="stylesheet" href="../input/data/minimal.css" type="text/css" /> <link rel="stylesheet" href="../input/data/responsive.css" type="text/css" /> diff --git a/docutils/test/functional/expected/pep_html.html b/docutils/test/functional/expected/pep_html.html index a67ec4744..bf3b009cf 100644 --- a/docutils/test/functional/expected/pep_html.html +++ b/docutils/test/functional/expected/pep_html.html @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- diff --git a/docutils/test/functional/expected/rst_html5_tuftig.html b/docutils/test/functional/expected/rst_html5_tuftig.html index 4a9174778..ab0531b37 100644 --- a/docutils/test/functional/expected/rst_html5_tuftig.html +++ b/docutils/test/functional/expected/rst_html5_tuftig.html @@ -2,8 +2,8 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta charset="utf-8" /> -<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="generator" content="Docutils 0.19.1b.dev: https://docutils.sourceforge.io/" /> +<meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Special Features of the tuftig.css Stylesheet</title> <link rel="stylesheet" href="../input/data/minimal.css" type="text/css" /> <link rel="stylesheet" href="../input/data/tuftig.css" type="text/css" /> diff --git a/docutils/test/functional/expected/standalone_rst_html4css1.html b/docutils/test/functional/expected/standalone_rst_html4css1.html index 2b2d70823..be0d61105 100644 --- a/docutils/test/functional/expected/standalone_rst_html4css1.html +++ b/docutils/test/functional/expected/standalone_rst_html4css1.html @@ -1,10 +1,9 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="Docutils 0.19.1b.dev: https://docutils.sourceforge.io/" /> -<title>reStructuredText Test Document</title> <meta content="reStructuredText, test, parser" name="keywords" /> <meta content="A test document, containing at least one example of each reStructuredText construct." lang="en" name="description" /> <meta name="author" content="David Goodger" /> @@ -12,6 +11,7 @@ <meta name="organization" content="humankind" /> <meta name="date" content="Now, or yesterday. Or maybe even before yesterday." /> <meta name="copyright" content="This document has been placed in the public domain. You may do with it as you wish. You may copy, modify, redistribute, reattribute, sell, buy, rent, lease, destroy, or improve it, quote it at length, excerpt, incorporate, collate, fold, staple, or mutilate it, or do anything else to it that your or anyone else's heart desires." /> +<title>reStructuredText Test Document</title> <link rel="stylesheet" href="../input/data/html4css1.css" type="text/css" /> <link rel="stylesheet" href="../input/data/math.css" type="text/css" /> </head> diff --git a/docutils/test/functional/expected/standalone_rst_html5.html b/docutils/test/functional/expected/standalone_rst_html5.html index 96e30d51b..0befeebec 100644 --- a/docutils/test/functional/expected/standalone_rst_html5.html +++ b/docutils/test/functional/expected/standalone_rst_html5.html @@ -2,9 +2,8 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta charset="utf-8" /> -<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="generator" content="Docutils 0.19.1b.dev: https://docutils.sourceforge.io/" /> -<title>reStructuredText Test Document</title> +<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta content="reStructuredText, test, parser" name="keywords" /> <meta content="A test document, containing at least one example of each reStructuredText construct." lang="en" name="description" xml:lang="en" /> <meta name="author" content="David Goodger" /> @@ -13,6 +12,7 @@ <meta name="author" content="I" /> <meta name="dcterms.date" content="Now, or yesterday. Or maybe even before yesterday." /> <meta name="dcterms.rights" content="This document has been placed in the public domain. You may do with it as you wish. You may copy, modify, redistribute, reattribute, sell, buy, rent, lease, destroy, or improve it, quote it at length, excerpt, incorporate, collate, fold, staple, or mutilate it, or do anything else to it that your or anyone else's heart desires." /> +<title>reStructuredText Test Document</title> <link rel="schema.dcterms" href="http://purl.org/dc/terms/"/> <link rel="stylesheet" href="../input/data/minimal.css" type="text/css" /> <link rel="stylesheet" href="../input/data/plain.css" type="text/css" /> diff --git a/docutils/test/functional/expected/standalone_rst_s5_html_1.html b/docutils/test/functional/expected/standalone_rst_s5_html_1.html index b8f901745..d46d5115b 100644 --- a/docutils/test/functional/expected/standalone_rst_s5_html_1.html +++ b/docutils/test/functional/expected/standalone_rst_s5_html_1.html @@ -1,13 +1,13 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="Docutils 0.19.1b.dev: https://docutils.sourceforge.io/" /> <meta name="version" content="S5 1.1" /> -<title>Slide Shows</title> <meta name="author" content="David Goodger" /> <meta name="date" content="2005-11-28" /> +<title>Slide Shows</title> <link rel="stylesheet" href="../input/data/html4css1.css" type="text/css" /> <!-- configuration parameters --> <meta name="defaultView" content="slideshow" /> diff --git a/docutils/test/functional/expected/standalone_rst_s5_html_2.html b/docutils/test/functional/expected/standalone_rst_s5_html_2.html index b972d0f56..78afd07cc 100644 --- a/docutils/test/functional/expected/standalone_rst_s5_html_2.html +++ b/docutils/test/functional/expected/standalone_rst_s5_html_2.html @@ -1,13 +1,13 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="Docutils 0.19.1b.dev: https://docutils.sourceforge.io/" /> <meta name="version" content="S5 1.1" /> -<title>Slide Shows</title> <meta name="author" content="David Goodger" /> <meta name="date" content="2005-11-28" /> +<title>Slide Shows</title> <link rel="stylesheet" href="../input/data/html4css1.css" type="text/css" /> <!-- configuration parameters --> <meta name="defaultView" content="slideshow" /> diff --git a/docutils/test/test_writers/test_html4css1_parts.py b/docutils/test/test_writers/test_html4css1_parts.py index 8aa9da3f2..23eb4334a 100755 --- a/docutils/test/test_writers/test_html4css1_parts.py +++ b/docutils/test/test_writers/test_html4css1_parts.py @@ -54,7 +54,7 @@ class Html4WriterPublishPartsTestCase(unittest.TestCase): + standard_generator_template) standard_meta_value = standard_html_meta_value % 'utf-8' standard_html_prolog = ( - '<?xml version="1.0" encoding="%s" ?>\n' + '<?xml version="1.0" encoding="%s"?>\n' '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n') @@ -236,8 +236,8 @@ Some stuff </table> <p>Some stuff</p> </div>\n''', - 'html_head': '''...<title>Title</title> -<meta name="author" content="me" />\n''', + 'html_head': '''...<meta name="author" content="me" /> +<title>Title</title>\n''', 'html_title': '''<h1 class="title">Title</h1>\n''', 'meta': '''<meta name="author" content="me" />\n''', 'title': '''Title''' diff --git a/docutils/test/test_writers/test_html4css1_template.py b/docutils/test/test_writers/test_html4css1_template.py index 0370c8b10..4113dd443 100755 --- a/docutils/test/test_writers/test_html4css1_template.py +++ b/docutils/test/test_writers/test_html4css1_template.py @@ -22,6 +22,7 @@ TEST_ROOT = os.path.abspath(os.path.join(__file__, '..', '..')) class WriterPublishTestCase(unittest.TestCase): + # maxDiff = None def test_publish(self): writer_name = 'html4' template_path = os.path.join(TEST_ROOT, 'data', 'full-template.txt') @@ -71,7 +72,7 @@ Section Some text. """, fr'''head_prefix = """\ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>""" @@ -80,8 +81,8 @@ fr'''head_prefix = """\ head = """\ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="Docutils {docutils.__version__}: https://docutils.sourceforge.io/" /> -<title>Document Title</title> -<meta name="author" content="Me" />""" +<meta name="author" content="Me" /> +<title>Document Title</title>""" stylesheet = """\ @@ -128,7 +129,7 @@ footer text head_prefix = """\ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>""" @@ -137,8 +138,8 @@ head_prefix = """\ head = """\ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="Docutils {docutils.__version__}: https://docutils.sourceforge.io/" /> -<title>Document Title</title> -<meta name="author" content="Me" />""" +<meta name="author" content="Me" /> +<title>Document Title</title>""" stylesheet = """\ @@ -217,15 +218,15 @@ fragment = """\ html_prolog = """\ -<?xml version="1.0" encoding="%s" ?> +<?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">""" html_head = """\ <meta http-equiv="Content-Type" content="text/html; charset=%s" /> <meta name="generator" content="Docutils {docutils.__version__}: https://docutils.sourceforge.io/" /> -<title>Document Title</title> -<meta name="author" content="Me" />""" +<meta name="author" content="Me" /> +<title>Document Title</title>""" html_title = """\ diff --git a/docutils/test/test_writers/test_html5_polyglot_parts.py b/docutils/test/test_writers/test_html5_polyglot_parts.py index 95011ca7d..c5925e14c 100644 --- a/docutils/test/test_writers/test_html5_polyglot_parts.py +++ b/docutils/test/test_writers/test_html5_polyglot_parts.py @@ -21,10 +21,9 @@ import docutils.core class Html5WriterPublishPartsTestCase(unittest.TestCase): + """Test case for HTML writer via the publish_parts interface.""" - """ - Test case for HTML writer via the publish_parts interface. - """ + # maxDiff = None def test_publish(self): writer_name = 'html5' @@ -52,8 +51,8 @@ class Html5WriterPublishPartsTestCase(unittest.TestCase): ' content="width=device-width, initial-scale=1" />\n' standard_html_meta_value = (standard_content_type_template - + standard_viewport_template - + standard_generator_template) + + standard_generator_template + + standard_viewport_template) standard_meta_value = standard_html_meta_value % 'utf-8' standard_html_prolog = '<!DOCTYPE html>\n' @@ -235,8 +234,8 @@ Some stuff </dl> <p>Some stuff</p> </main>\n''', - 'html_head': '''...<title>Title</title> -<meta name="author" content="me" />\n''', + 'html_head': '''...<meta name="author" content="me" /> +<title>Title</title>\n''', 'html_title': '''<h1 class="title">Title</h1>\n''', 'meta': '''<meta name="author" content="me" />\n''', 'title': '''Title''' diff --git a/docutils/test/test_writers/test_html5_template.py b/docutils/test/test_writers/test_html5_template.py index 4fb38b6e6..857400183 100644 --- a/docutils/test/test_writers/test_html5_template.py +++ b/docutils/test/test_writers/test_html5_template.py @@ -22,6 +22,7 @@ TEST_ROOT = os.path.abspath(os.path.join(__file__, '..', '..')) class WriterPublishTestCase(unittest.TestCase): + # maxDiff = None def test_publish(self): writer_name = 'html5' template_path = os.path.join(TEST_ROOT, 'data', 'full-template.txt') @@ -78,10 +79,10 @@ fr'''head_prefix = """\ head = """\ <meta charset="utf-8" /> -<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="generator" content="Docutils {docutils.__version__}: https://docutils.sourceforge.io/" /> -<title>Document Title</title> -<meta name="author" content="Me" />""" +<meta name="viewport" content="width=device-width, initial-scale=1" /> +<meta name="author" content="Me" /> +<title>Document Title</title>""" stylesheet = """\ @@ -130,10 +131,10 @@ head_prefix = """\ head = """\ <meta charset="utf-8" /> -<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="generator" content="Docutils {docutils.__version__}: https://docutils.sourceforge.io/" /> -<title>Document Title</title> -<meta name="author" content="Me" />""" +<meta name="viewport" content="width=device-width, initial-scale=1" /> +<meta name="author" content="Me" /> +<title>Document Title</title>""" stylesheet = """\ @@ -194,8 +195,8 @@ footer = """\ meta = """\ <meta charset="utf-8" /> -<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="generator" content="Docutils {docutils.__version__}: https://docutils.sourceforge.io/" /> +<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="author" content="Me" />""" @@ -212,10 +213,10 @@ html_prolog = """\ html_head = """\ <meta charset="%s" /> -<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="generator" content="Docutils {docutils.__version__}: https://docutils.sourceforge.io/" /> -<title>Document Title</title> -<meta name="author" content="Me" />""" +<meta name="viewport" content="width=device-width, initial-scale=1" /> +<meta name="author" content="Me" /> +<title>Document Title</title>""" html_title = """\ diff --git a/docutils/test/test_writers/test_s5.py b/docutils/test/test_writers/test_s5.py index b9a854271..904aecd97 100755 --- a/docutils/test/test_writers/test_s5.py +++ b/docutils/test/test_writers/test_s5.py @@ -77,7 +77,7 @@ First Slide Slide text. """, f"""\ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> @@ -142,7 +142,7 @@ totest_2['settings'] = [ We're just checking the settings """, f"""\ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> |
