From 1530251f0c661de36c88ca84a5985593629f20d3 Mon Sep 17 00:00:00 2001
From: wiemann
Date: Tue, 16 Jan 2007 01:51:28 +0000
Subject: + - Moved ``id`` attributes from titles to surrounding ``div`` +
elements; dropped ``name`` attributes (``id`` is universally + supported
now).
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@4883 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
---
HISTORY.txt | 3 +
docutils/writers/html4css1/__init__.py | 41 ++---
docutils/writers/s5_html/__init__.py | 4 +-
test/functional/expected/pep_html.html | 16 +-
.../expected/standalone_rst_html4css1.html | 166 ++++++++++-----------
.../expected/standalone_rst_s5_html_1.html | 4 +-
.../expected/standalone_rst_s5_html_2.html | 4 +-
test/test_writers/test_html4css1_parts.py | 48 +++---
test/test_writers/test_html4css1_template.py | 16 +-
9 files changed, 142 insertions(+), 160 deletions(-)
diff --git a/HISTORY.txt b/HISTORY.txt
index 569e717a8..a68568e93 100644
--- a/HISTORY.txt
+++ b/HISTORY.txt
@@ -78,6 +78,9 @@ Changes Since 0.4
- Moved template functionality from the PEP/HTML writer here.
- Expanded the fragments available in the ``parts`` attribute.
+ - Moved ``id`` attributes from titles to surrounding ``div``
+ elements; dropped ``name`` attributes (``id`` is universally
+ supported now).
* docutils/writers/html4css1/template.txt: Added to project.
diff --git a/docutils/writers/html4css1/__init__.py b/docutils/writers/html4css1/__init__.py
index 22fb85747..59e8adabb 100644
--- a/docutils/writers/html4css1/__init__.py
+++ b/docutils/writers/html4css1/__init__.py
@@ -407,12 +407,6 @@ class HTMLTranslator(nodes.NodeVisitor):
"""Construct and return an XML-compatible empty tag."""
return self.starttag(node, tagname, suffix, empty=1, **attributes)
- # !!! to be removed in Docutils 0.5 (change calls to use "starttag"):
- def start_tag_with_title(self, node, tagname, **atts):
- """ID and NAME attributes will be handled in the title."""
- node = {'classes': node.get('classes', [])}
- return self.starttag(node, tagname, **atts)
-
def set_class_on_child(self, node, class_, index=0):
"""
Set class `class_` on the visible child no. index of `node`.
@@ -462,7 +456,7 @@ class HTMLTranslator(nodes.NodeVisitor):
self.depart_docinfo_item()
def visit_admonition(self, node):
- self.body.append(self.start_tag_with_title(node, 'div'))
+ self.body.append(self.starttag(node, 'div'))
self.set_first_last(node)
def depart_admonition(self, node=None):
@@ -721,6 +715,7 @@ class HTMLTranslator(nodes.NodeVisitor):
self.html_body.extend(self.body_prefix[1:] + self.body_pre_docinfo
+ self.docinfo + self.body
+ self.body_suffix[:-1])
+ assert not self.context, 'internal error: context not empty'
def visit_emphasis(self, node):
self.body.append('')
@@ -1264,7 +1259,7 @@ class HTMLTranslator(nodes.NodeVisitor):
def visit_section(self, node):
self.section_level += 1
self.body.append(
- self.start_tag_with_title(node, 'div', CLASS='section'))
+ self.starttag(node, 'div', CLASS='section'))
def depart_section(self, node):
self.section_level -= 1
@@ -1272,7 +1267,7 @@ class HTMLTranslator(nodes.NodeVisitor):
def visit_sidebar(self, node):
self.body.append(
- self.start_tag_with_title(node, 'div', CLASS='sidebar'))
+ self.starttag(node, 'div', CLASS='sidebar'))
self.set_first_last(node)
self.in_sidebar = 1
@@ -1429,30 +1424,26 @@ class HTMLTranslator(nodes.NodeVisitor):
def depart_thead(self, node):
self.body.append('\n')
- def visit_title(self, node, move_ids=1):
+ def visit_title(self, node):
"""Only 6 section levels are supported by HTML."""
check_id = 0
close_tag = '
\n'
if isinstance(node.parent, nodes.topic):
self.body.append(
self.starttag(node, 'p', '', CLASS='topic-title first'))
- check_id = 1
elif isinstance(node.parent, nodes.sidebar):
self.body.append(
self.starttag(node, 'p', '', CLASS='sidebar-title'))
- check_id = 1
elif isinstance(node.parent, nodes.Admonition):
self.body.append(
self.starttag(node, 'p', '', CLASS='admonition-title'))
- check_id = 1
elif isinstance(node.parent, nodes.table):
self.body.append(
self.starttag(node, 'caption', ''))
- check_id = 1
close_tag = '\n'
elif isinstance(node.parent, nodes.document):
self.body.append(self.starttag(node, 'h1', '', CLASS='title'))
- self.context.append('\n')
+ close_tag = '\n'
self.in_document_title = len(self.body)
else:
assert isinstance(node.parent, nodes.section)
@@ -1464,27 +1455,15 @@ class HTMLTranslator(nodes.NodeVisitor):
self.body.append(
self.starttag(node, 'h%s' % h_level, '', **atts))
atts = {}
- # !!! conditional to be removed in Docutils 0.5:
- if move_ids:
- if node.parent['ids']:
- atts['ids'] = node.parent['ids']
if node.hasattr('refid'):
atts['class'] = 'toc-backref'
atts['href'] = '#' + node['refid']
if atts:
self.body.append(self.starttag({}, 'a', '', **atts))
- self.context.append('\n' % (h_level))
- else:
- self.context.append('\n' % (h_level))
- # !!! conditional to be removed in Docutils 0.5:
- if check_id:
- if node.parent['ids']:
- atts={'ids': node.parent['ids']}
- self.body.append(
- self.starttag({}, 'a', '', **atts))
- self.context.append('' + close_tag)
+ close_tag = '\n' % (h_level)
else:
- self.context.append(close_tag)
+ close_tag = '\n' % (h_level)
+ self.context.append(close_tag)
def depart_title(self, node):
self.body.append(self.context.pop())
@@ -1502,7 +1481,7 @@ class HTMLTranslator(nodes.NodeVisitor):
self.body.append('')
def visit_topic(self, node):
- self.body.append(self.start_tag_with_title(node, 'div', CLASS='topic'))
+ self.body.append(self.starttag(node, 'div', CLASS='topic'))
self.topic_classes = node['classes']
def depart_topic(self, node):
diff --git a/docutils/writers/s5_html/__init__.py b/docutils/writers/s5_html/__init__.py
index 96a8df544..486c03f4a 100644
--- a/docutils/writers/s5_html/__init__.py
+++ b/docutils/writers/s5_html/__init__.py
@@ -333,5 +333,5 @@ class S5HTMLTranslator(html4css1.HTMLTranslator):
else:
html4css1.HTMLTranslator.visit_subtitle(self, node)
- def visit_title(self, node, move_ids=0):
- html4css1.HTMLTranslator.visit_title(self, node, move_ids=move_ids)
+ def visit_title(self, node):
+ html4css1.HTMLTranslator.visit_title(self, node)
diff --git a/test/functional/expected/pep_html.html b/test/functional/expected/pep_html.html
index 716b11d0c..7f55af60c 100644
--- a/test/functional/expected/pep_html.html
+++ b/test/functional/expected/pep_html.html
@@ -54,25 +54,25 @@ to templates. DO NOT USE THIS HTML FILE AS YOUR TEMPLATE!
-
-
Contents
+
-
-
+
-
-
+
+
This document has been placed in the public domain.
-