diff options
author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2013-05-07 10:52:59 +0000 |
---|---|---|
committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2013-05-07 10:52:59 +0000 |
commit | dd795c63c08c8d381145fe3f15081335d64b94e1 (patch) | |
tree | 3b022dd3c0b964a83af5d53b7fcab83c01f50efa | |
parent | 3e81ca1494ff3763ff365f2f58a5cd1f0cb226de (diff) | |
download | docutils-dd795c63c08c8d381145fe3f15081335d64b94e1.tar.gz |
Avoid repeated class declarations in html4css1 writer
Modified version of patch [ 104 ].
HtmlTranslator.starttag() no longer adds class arguments to the node.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7661 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r-- | HISTORY.txt | 2 | ||||
-rw-r--r-- | docutils/writers/html4css1/__init__.py | 23 |
2 files changed, 14 insertions, 11 deletions
diff --git a/HISTORY.txt b/HISTORY.txt index 17f639217..caf27367c 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -55,6 +55,8 @@ Changes Since 0.10 where stylesheets are found. Used by `stylesheet_path` when expanding relative path arguments. - New default for math-output_: ``HTML math.css``. + - Avoid repeated class declarations in html4css1 writer + (modified version of patch [ 104 ]). .. _math-output: docs/user/config.html#math-output diff --git a/docutils/writers/html4css1/__init__.py b/docutils/writers/html4css1/__init__.py index bf0749428..f91a24983 100644 --- a/docutils/writers/html4css1/__init__.py +++ b/docutils/writers/html4css1/__init__.py @@ -402,19 +402,19 @@ class HTMLTranslator(nodes.NodeVisitor): ids = [] for (name, value) in attributes.items(): atts[name.lower()] = value - classes = node.get('classes', []) - if 'class' in atts: - classes.append(atts.pop('class')) - # move language specification to 'lang' attribute - languages = [cls for cls in classes - if cls.startswith('language-')] + classes = [] + languages = [] + # unify class arguments and move language specification + for cls in node.get('classes', []) + atts.pop('class', '').split() : + if cls.startswith('language-'): + languages.append(cls[9:]) + elif cls.strip() and cls not in classes: + classes.append(cls) if languages: # attribute name is 'lang' in XHTML 1.0 but 'xml:lang' in 1.1 - atts[self.lang_attribute] = languages[0][9:] - classes.pop(classes.index(languages[0])) - classes = ' '.join(classes).strip() + atts[self.lang_attribute] = languages[0] if classes: - atts['class'] = classes + atts['class'] = ' '.join(classes) assert 'id' not in atts ids.extend(node.get('ids', [])) if 'ids' in atts: @@ -906,7 +906,8 @@ class HTMLTranslator(nodes.NodeVisitor): and len(node.astext()) > self.settings.field_name_limit): atts['colspan'] = 2 self.context.append('</tr>\n' - + self.starttag(node.parent, 'tr', '') + + self.starttag(node.parent, 'tr', '', + CLASS='field') + '<td> </td>') else: self.context.append('') |