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

+ -
-

Abstract

+
+

Abstract

This is just a test [1]. See the PEP repository [2] for the real thing.

-
-

Copyright

+ -
-

References and Footnotes

+
+

References and Footnotes

diff --git a/test/functional/expected/standalone_rst_html4css1.html b/test/functional/expected/standalone_rst_html4css1.html index 5c1c2072a..6ceb439cc 100644 --- a/test/functional/expected/standalone_rst_html4css1.html +++ b/test/functional/expected/standalone_rst_html4css1.html @@ -82,8 +82,8 @@ transforms to after the document title, subtitle, and docinfo. --> -
-

Table of Contents

+
+

Table of Contents

-
-

1   Structural Elements

-
-

1.1   Section Title

+
+

1   Structural Elements

+
+

1.1   Section Title

Section Subtitle

That's it, the text just above this line.

-
-

1.2   Empty Section

+ -
-

1.3   Transitions

+
+

1.3   Transitions

Here's a transition:


It divides the section. Transitions may also occur between sections:


-
-

2   Body Elements

-
-

2.1   Paragraphs

+
+

2   Body Elements

+
+

2.1   Paragraphs

A paragraph.

-
-

2.1.1   Inline Markup

+
+

2.1.1   Inline Markup

Paragraphs contain text and may contain inline markup: emphasis, strong emphasis, inline literals, standalone hyperlinks (http://www.python.org), external hyperlinks (Python [5]), internal @@ -191,8 +191,8 @@ and explicit roles for standard inline live link to PEP 258 here.

-
-

2.2   Bullet Lists

+
+

2.2   Bullet Lists

  • A bullet list

      @@ -216,8 +216,8 @@ live link to PEP 258 here.

-
-

2.3   Enumerated Lists

+
+

2.3   Enumerated Lists

  1. Arabic numerals.

      @@ -249,8 +249,8 @@ live link to PEP 258 here.

-
-

2.4   Definition Lists

+
+

2.4   Definition Lists

Term
Definition
@@ -264,8 +264,8 @@ live link to PEP 258 here.

Definition
-
@@ -288,8 +288,8 @@ doesn't get stripped away.)

-
-

2.6   Option Lists

+
+

2.6   Option Lists

For listing command-line options:

@@ -334,8 +334,8 @@ regardless of where it starts.

There must be at least two spaces between the option and the description.

-
-

2.7   Literal Blocks

+
+

2.7   Literal Blocks

Literal blocks are indicated with a double-colon ("::") at the end of the preceding paragraph (over there -->). They can be indented:

@@ -351,8 +351,8 @@ if literal_block:
 > Why didn't I think of that?
 
-
-

2.8   Line Blocks

+
+

2.8   Line Blocks

This section tests line blocks. Line blocks are body elements which consist of lines and other line blocks. Nested line blocks cause indentation.

@@ -410,8 +410,8 @@ the left edge of the text above it.
-
-

2.9   Block Quotes

+
+

2.9   Block Quotes

Block quotes consist of indented body elements:

My theory by A. Elk. Brackets Miss, brackets. This theory goes @@ -422,8 +422,8 @@ own it, and what it is too.

—Anne Elk (Miss)

-
-

2.10   Doctest Blocks

+
+

2.10   Doctest Blocks

 >>> print 'Python-specific usage examples; begun with ">>>"'
 Python-specific usage examples; begun with ">>>"
@@ -431,8 +431,8 @@ Python-specific usage examples; begun with ">>>"
 (cut and pasted from interactive Python sessions)
 
-
@@ -483,8 +483,8 @@ nonexistent footnote: -

2.12   Citations

+
@@ -495,8 +495,8 @@ rendered separately and differently from footnotes.

Here's a reference to the above, [CIT2002], and a [nonexistent]_ citation.

-
-

2.13   Targets

+
+

2.13   Targets

This paragraph is pointed to by the explicit "example" target. A reference can be found under Inline Markup, above. Inline hyperlink targets are also possible.

@@ -508,22 +508,22 @@ hyperlink targets are also possible.

refer to the Targets section.

Here's a `hyperlink reference without a target`_, which generates an error.

-
-

2.13.1   Duplicate Target Names

+
+

2.13.1   Duplicate Target Names

Duplicate names in section headers or other implicit targets will generate "info" (level-1) system messages. Duplicate names in explicit targets will generate "warning" (level-2) system messages.

-
-

2.13.2   Duplicate Target Names

+
+

2.13.2   Duplicate Target Names

Since there are two "Duplicate Target Names" section headers, we cannot uniquely refer to either of them by name. If we try to (like this: `Duplicate Target Names`_), an error is generated.

-
-

2.14   Directives

-
+
+

2.14   Directives

+
@@ -699,12 +699,12 @@ background color.

-
-

2.14.6   Replacement Text

+ -
-

2.14.7   Compound Paragraph

+
+

2.14.7   Compound Paragraph

Compound 1, paragraph 1.

Compound 1, paragraph 2.

@@ -771,8 +771,8 @@ paragraph.

Compound 7, another paragraph.

-
-

2.14.8   Parsed Literal Blocks

+
+

2.14.8   Parsed Literal Blocks

 This is a parsed literal block.
     This line is indented.  The next line is blank.
@@ -782,13 +782,13 @@ Inline markup is supported, e.g. emphasis, strong, 
 
-
-

2.15   Substitution Definitions

+
+

2.15   Substitution Definitions

An inline image (EXAMPLE) example:

(Substitution definitions are not visible in the HTML source.)

-
-

2.16   Comments

+
+

2.16   Comments

Here's one:

(View the HTML source to see the comment.)

-
-

2.17   Raw text

+
+

2.17   Raw text

This does not necessarily look nice, because there may be missing white space.

It's just there to freeze the behavior.

A test.Second test.
Another test with myclass set.

This is the fourth test with myrawroleclass set.

Fifth test in HTML.
Line two.
-
-

2.18   Container

+
+

2.18   Container

paragraph 1

paragraph 2

-
-

2.19   Colspanning tables

+
+

2.19   Colspanning tables

This table has a cell spanning two columns:

@@ -850,8 +850,8 @@ Fifth test in HTML.
Line two.
-
-

2.20   Rowspanning tables

+
+

2.20   Rowspanning tables

Here's a table with cells spanning several rows:

@@ -883,8 +883,8 @@ cell.
-
-

2.21   Complex tables

+
+

2.21   Complex tables

Here's a complex table, which should test all features.

@@ -932,8 +932,8 @@ empty: -->
-
-

2.22   List Tables

+
+

2.22   List Tables

Here's a list table exercising all features:

@@ -965,8 +965,8 @@ crunchy, now would it?
list table with integral header
-
-

2.23   Custom Roles

+
+

2.23   Custom Roles

  • A role based on an existing role.

    one two three

    @@ -983,8 +983,8 @@ crunchy, now would it?
-
-

3   Error Handling

+
+

3   Error Handling

Any errors caught during processing will generate system messages.

There should be five messages in the following, auto-generated section, "Docutils System Messages":

diff --git a/test/functional/expected/standalone_rst_s5_html_1.html b/test/functional/expected/standalone_rst_s5_html_1.html index a3e4e4bb5..b0119ab25 100644 --- a/test/functional/expected/standalone_rst_s5_html_1.html +++ b/test/functional/expected/standalone_rst_s5_html_1.html @@ -68,8 +68,8 @@ ============================ --> -
-

Contents

+
+

Contents

  • Introduction
  • Features (1)
  • diff --git a/test/functional/expected/standalone_rst_s5_html_2.html b/test/functional/expected/standalone_rst_s5_html_2.html index fdf4b7ef0..6a3d72b5e 100644 --- a/test/functional/expected/standalone_rst_s5_html_2.html +++ b/test/functional/expected/standalone_rst_s5_html_2.html @@ -64,8 +64,8 @@ ============================ --> -
    -

    Contents

    +
    +

    Contents

    • Introduction
    • Features (1)
    • diff --git a/test/test_writers/test_html4css1_parts.py b/test/test_writers/test_html4css1_parts.py index b1c6a3dbb..add7a2d39 100755 --- a/test/test_writers/test_html4css1_parts.py +++ b/test/test_writers/test_html4css1_parts.py @@ -118,11 +118,11 @@ And even more stuff """, """\ {'fragment': '''

      Some stuff

      -
      -

      Section

      +
      +

      Section

      Some more stuff

      -
      -

      Another Section

      +
      +

      Another Section

      And even more stuff

      \\n''', @@ -130,11 +130,11 @@ And even more stuff

      Title

      Subtitle

      Some stuff

      -
      -

      Section

      +
      +

      Section

      Some more stuff

      -
      -

      Another Section

      +
      +

      Another Section

      And even more stuff

      @@ -265,32 +265,32 @@ Another Section And even more stuff """, """\ -{'fragment': '''
      -

      Title

      -
      -

      Not A Subtitle

      +{'fragment': '''
      +

      Title

      +
      +

      Not A Subtitle

      Some stuff

      -
      -

      Section

      +
      +

      Section

      Some more stuff

      -
      -

      Another Section

      +
      +

      Another Section

      And even more stuff

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

      Title

      -
      -

      Not A Subtitle

      +
      +

      Title

      +
      +

      Not A Subtitle

      Some stuff

      -
      -

      Section

      +
      +

      Section

      Some more stuff

      -
      -

      Another Section

      +
      +

      Another Section

      And even more stuff

      diff --git a/test/test_writers/test_html4css1_template.py b/test/test_writers/test_html4css1_template.py index 6df069688..98714fde6 100755 --- a/test/test_writers/test_html4css1_template.py +++ b/test/test_writers/test_html4css1_template.py @@ -81,8 +81,8 @@ docinfo = """\ body = """\ -
      -

      Section

      +
      +

      Section

      Some text.

      """ @@ -138,8 +138,8 @@ docinfo = """\ body = """\ -
      -

      Section

      +
      +

      Section

      Some text.

      """ @@ -180,8 +180,8 @@ meta = """\ fragment = """\ -
      -

      Section

      +
      +

      Section

      Some text.

      """ @@ -218,8 +218,8 @@ html_body = """\ Me -
      -

      Section

      +
      +

      Section

      Some text.

      -- cgit v1.2.1