diff options
| author | goodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2005-12-15 14:32:01 +0000 |
|---|---|---|
| committer | goodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2005-12-15 14:32:01 +0000 |
| commit | 185f2b4fb839e4044c32afdbbbefd86f552a85a1 (patch) | |
| tree | 845ef25c6a0cd3523da973d626d9791ea0640d85 | |
| parent | 1c853088b607301dedcaf149efe38a3d12ba4db1 (diff) | |
| download | docutils-185f2b4fb839e4044c32afdbbbefd86f552a85a1.tar.gz | |
fixed "compact" & "open" classes on lists, and added a functional test
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@4219 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
| -rw-r--r-- | docutils/docutils/writers/html4css1/__init__.py | 42 | ||||
| -rw-r--r-- | docutils/test/functional/expected/compact_lists.html | 47 | ||||
| -rw-r--r-- | docutils/test/functional/input/compact_lists.txt | 39 | ||||
| -rw-r--r-- | docutils/test/functional/tests/compact_lists.py | 11 |
4 files changed, 122 insertions, 17 deletions
diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py index fe1490ab3..02833d66a 100644 --- a/docutils/docutils/writers/html4css1/__init__.py +++ b/docutils/docutils/writers/html4css1/__init__.py @@ -501,17 +501,20 @@ class HTMLTranslator(nodes.NodeVisitor): else: return 1 + def is_compactable(self, node): + return ('compact' in node['classes'] + or (self.settings.compact_lists + and 'open' not in node['classes'] + and (self.compact_simple + or self.topic_classes == ['contents'] + or self.check_simple_list(node)))) + def visit_bullet_list(self, node): atts = {} old_compact_simple = self.compact_simple self.context.append((self.compact_simple, self.compact_p)) self.compact_p = None - self.compact_simple = ('compact' in node['classes'] - or (self.settings.compact_lists - and 'open' not in node['classes'] - and (self.compact_simple - or self.topic_classes == ['contents'] - or self.check_simple_list(node)))) + self.compact_simple = self.is_compactable(node) if self.compact_simple and not old_compact_simple: atts['class'] = 'simple' self.body.append(self.starttag(node, 'ul', **atts)) @@ -763,12 +766,7 @@ class HTMLTranslator(nodes.NodeVisitor): old_compact_simple = self.compact_simple self.context.append((self.compact_simple, self.compact_p)) self.compact_p = None - self.compact_simple = ('compact' in node['classes'] - or (self.settings.compact_lists - and 'open' not in node['classes'] - and (self.compact_simple - or self.topic_classes == ['contents'] - or self.check_simple_list(node)))) + self.compact_simple = self.is_compactable(node) if self.compact_simple and not old_compact_simple: atts['class'] = (atts.get('class', '') + ' simple').strip() self.body.append(self.starttag(node, 'ol', **atts)) @@ -812,6 +810,7 @@ class HTMLTranslator(nodes.NodeVisitor): elif (self.settings.compact_field_lists and 'open' not in node['classes']): self.compact_field_list = 1 + if self.compact_field_list: for field in node: field_body = field[-1] assert isinstance(field_body, nodes.field_body) @@ -1187,11 +1186,20 @@ class HTMLTranslator(nodes.NodeVisitor): ([], ['first'], ['last'], ['first', 'last']))): # Attribute which needs to survive. return 0 - if (self.compact_simple or - self.compact_field_list or - self.compact_p and (len(node.parent) == 1 or - len(node.parent) == 2 and - isinstance(node.parent[0], nodes.label))): + 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 + if ( self.compact_simple + or self.compact_field_list + or (self.compact_p + and (len(node.parent) == 1 + or len(node.parent) == 2 + and isinstance(node.parent[0], nodes.label)))): return 1 return 0 diff --git a/docutils/test/functional/expected/compact_lists.html b/docutils/test/functional/expected/compact_lists.html new file mode 100644 index 000000000..968df354d --- /dev/null +++ b/docutils/test/functional/expected/compact_lists.html @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="generator" content="Docutils 0.3.10: http://docutils.sourceforge.net/" /> +<title></title> +<link rel="stylesheet" href="../../../docutils/writers/html4css1/html4css1.css" type="text/css" /> +</head> +<body> +<div class="document"> +<ul class="simple"> +<li>This is an ordinary simple bullet list.</li> +<li>It should be made compact (<p> & </p> tags omitted).</li> +</ul> +<hr class="docutils" /> +<ul> +<li><p class="first">This is a bullet list that is not simple.</p> +<p>There are multiple paragraphs in some items.</p> +</li> +<li><p class="first">It should not be made compact.</p> +</li> +<li><p class="first">Even though some items may have only one paragraph.</p> +</li> +</ul> +<hr class="docutils" /> +<ul class="open"> +<li><p class="first">This is a simple bullet list, but class="open" is set.</p> +</li> +<li><p class="first">It should not be made compact.</p> +</li> +</ul> +<hr class="docutils" /> +<ul class="compact simple"> +<li>This is a bullet list that is not simple.<p>There are multiple paragraphs in some items.</p> +</li> +<li>However, the class="compact" setting will cause +all first paragraph's <p> & </p> tags to be omitted.</li> +<li>Items with multiple paragraphs will not appear changed.</li> +<li>Items may have one paragraph, or multiple.<p>Items with multiple paragraphs will still be followed +by vertical whitespace because of the later paragraphs.</p> +</li> +<li>The effect is interesting.</li> +</ul> +</div> +</body> +</html> diff --git a/docutils/test/functional/input/compact_lists.txt b/docutils/test/functional/input/compact_lists.txt new file mode 100644 index 000000000..ec13a97be --- /dev/null +++ b/docutils/test/functional/input/compact_lists.txt @@ -0,0 +1,39 @@ +* This is an ordinary simple bullet list. +* It should be made compact (<p> & </p> tags omitted). + +********** + +* This is a bullet list that is not simple. + + There are multiple paragraphs in some items. + +* It should not be made compact. + +* Even though some items may have only one paragraph. + +********** + +.. class:: open + +* This is a simple bullet list, but class="open" is set. +* It should not be made compact. + +********** + +.. class:: compact + +* This is a bullet list that is not simple. + + There are multiple paragraphs in some items. + +* However, the class="compact" setting will cause + all first paragraph's <p> & </p> tags to be omitted. + +* Items with multiple paragraphs will not appear changed. + +* Items may have one paragraph, or multiple. + + Items with multiple paragraphs will still be followed + by vertical whitespace because of the later paragraphs. + +* The effect is interesting. diff --git a/docutils/test/functional/tests/compact_lists.py b/docutils/test/functional/tests/compact_lists.py new file mode 100644 index 000000000..3ac4c3f8b --- /dev/null +++ b/docutils/test/functional/tests/compact_lists.py @@ -0,0 +1,11 @@ +# Source and destination file names. +test_source = "compact_lists.txt" +test_destination = "compact_lists.html" + +# Keyword parameters passed to publish_file. +reader_name = "standalone" +parser_name = "rst" +writer_name = "html" + +# Settings +#settings_overrides['key'] = |
