diff options
-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('') |