From f6f47f66f31a8a55a0fd0e4f0a4edf077ad2b9ac Mon Sep 17 00:00:00 2001 From: milde Date: Wed, 12 Sep 2012 21:16:15 +0000 Subject: [PATCH] Simplify handling of "code" inline nodes. git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk@7512 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- sandbox/html4strict/html4strict/__init__.py | 36 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/sandbox/html4strict/html4strict/__init__.py b/sandbox/html4strict/html4strict/__init__.py index 80ab83120..0627f33a1 100644 --- a/sandbox/html4strict/html4strict/__init__.py +++ b/sandbox/html4strict/html4strict/__init__.py @@ -168,7 +168,7 @@ class HTMLTranslator(html4css1.HTMLTranslator): def depart_docinfo(self, node): self.body.append('\n') - def visit_docinfo_item(self, node, name, meta=1): + def visit_docinfo_item(self, node, name, meta=True): if meta: meta_tag = '\n' \ % (name, self.attval(node.astext())) @@ -252,8 +252,8 @@ class HTMLTranslator(html4css1.HTMLTranslator): def depart_footnote(self, node): self.body.append('\n') - next_siblings = node.traverse(descend=0, siblings=1, - include_self=0) + next_siblings = node.traverse(descend=False, siblings=True, + include_self=False) next = next_siblings and next_siblings[0] if isinstance(next, nodes.footnote): self.body.append('<-- next footnote -->') @@ -298,8 +298,8 @@ class HTMLTranslator(html4css1.HTMLTranslator): # Content already processed: raise nodes.SkipNode - def depart_generated(self, node): - pass + # def depart_generated(self, node): + # pass # Do not mark the first child with 'class="first"' def visit_list_item(self, node): @@ -307,7 +307,13 @@ class HTMLTranslator(html4css1.HTMLTranslator): # inline literal def visit_literal(self, node): - """Process text to prevent in-word line wrapping.""" + # special case: "code" role + classes = node.get('classes', []) + if 'code' in classes: + # filter 'code' from class arguments + node['classes'] = [cls for cls in classes if cls != 'code'] + self.body.append(self.starttag(node, 'code', '')) + return self.body.append( self.starttag(node, 'tt', '', CLASS='literal')) text = node.astext() @@ -326,6 +332,10 @@ class HTMLTranslator(html4css1.HTMLTranslator): # Content already processed: raise nodes.SkipNode + def depart_literal(self, node): + # skipped unless literal element is from "code" role: + self.body.append('') + # literal block and doctest block: no newline after
 tag
     # (leads to blank line in XHTML1.1)
     def visit_literal_block(self, node,):
@@ -409,9 +419,9 @@ class HTMLTranslator(html4css1.HTMLTranslator):
                ):
             self.body.append('\n')
 
-
-    # no hard-coded border setting in the table head
-    # ----------------------------------------------
+    # tables
+    # ------
+    # no hard-coded border setting in the table head::
 
     def visit_table(self, node):
         classes = [cls.strip(u' \t\n')
@@ -420,6 +430,14 @@ class HTMLTranslator(html4css1.HTMLTranslator):
         self.body.append(tag)
 
 
+    # no hard-coded vertical alignment in table body::
+
+    def visit_tbody(self, node):
+        self.write_colspecs()
+        self.body.append(self.context.pop()) # '\n' or ''
+        self.body.append(self.starttag(node, 'tbody'))
+
+
 class SimpleListChecker(html4css1.SimpleListChecker):
 
     """
-- 
2.11.4.GIT