From c96a54c61dc11af802c64ff1ddd245eeb68b1512 Mon Sep 17 00:00:00 2001 From: smerch Date: Fri, 28 May 2010 15:34:02 +0300 Subject: [PATCH] Fix for .html writer logic --- sphinx/writers/html.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 3fe1326a9..dce00a379 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -16,6 +16,7 @@ import os from docutils import nodes from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator +from sphinx import addnodes from sphinx.locale import admonitionlabels, versionlabels, _ from sphinx.util.smartypants import sphinx_smarty_pants @@ -284,6 +285,47 @@ class HTMLTranslator(BaseTranslator): def depart_centered(self, node): self.body.append('

') + def should_be_compact_paragraph(self, node): + """ + Determine if the

tags around paragraph ``node`` can be omitted. + """ + if (isinstance(node.parent, nodes.document) or + isinstance(node.parent, nodes.compound) or + isinstance(node.parent, addnodes.desc_content)): + # Never compact paragraphs in document or compound. + # or desc_content items either. + return 0 + for key, value in node.attlist(): + if (node.is_not_default(key) and + not (key == 'classes' and value in + ([], ['first'], ['last'], ['first', 'last']))): + # Attribute which needs to survive. + return 0 + first = isinstance(node.parent[0], nodes.label) # skip label + for child in node.parent.children[first:]: + # only first paragraph can be compact + if isinstance(child, nodes.Invisible): + continue + if child is node: + break + return 0 + parent_length = len([n for n in node.parent if not isinstance( + n, (nodes.Invisible, nodes.label))]) + if ( self.compact_simple + or self.compact_field_list + or self.compact_p and parent_length == 1): + return 1 + return 0 + + def visit_paragraph(self, node): + if self.should_be_compact_paragraph(node): + self.context.append('') + else: + self.body.append(self.starttag(node, 'p', '')) + self.context.append('

\n') + def depart_paragraph(self, node): + self.body.append(self.context.pop()) + def visit_compact_paragraph(self, node): pass def depart_compact_paragraph(self, node):