From d72cb6efcbdfb8e567e3faa2ff6099ae7bfcbc9f Mon Sep 17 00:00:00 2001 From: milde Date: Thu, 26 Feb 2015 15:29:45 +0000 Subject: [PATCH] Fix [ 266 ] creating labels/class values in description list items. Also clarify the documentation of "class" directive and internal hyperlink targets applying to the next element also if at the end of an indented block. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@7804 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/HISTORY.txt | 1 + docutils/docs/ref/rst/directives.txt | 28 ++++++++++++--- docutils/docs/ref/rst/restructuredtext.txt | 27 ++++++++++++--- docutils/docutils/writers/html4css1/__init__.py | 8 ++++- docutils/test/test_writers/test_html4css1_misc.py | 42 +++++++++++++++++++++++ 5 files changed, 97 insertions(+), 9 deletions(-) diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt index 226566827..50c63bba7 100644 --- a/docutils/HISTORY.txt +++ b/docutils/HISTORY.txt @@ -38,6 +38,7 @@ Changes Since 0.12 - Add "docutils" to class values for "container" object to address [ 267 ]. - Apply patch [ 119 ] by Anatoly Techtonik: use absolute paths for ``default_stylesheet_path`` and ``default_template_path``. + - Fix [ 266 ] creating labels/class values in description list items. * docutils/writers/xhtml11/ diff --git a/docutils/docs/ref/rst/directives.txt b/docutils/docs/ref/rst/directives.txt index 582b5d0a3..2b07aae44 100644 --- a/docutils/docs/ref/rst/directives.txt +++ b/docutils/docs/ref/rst/directives.txt @@ -548,7 +548,7 @@ symbols, for example:: α_t(i) = P(O_1, O_2, … O_t, q_t = S_i λ) Support is limited to a subset of *LaTeX math* by the conversion -required for many output formats. For HTML, the the `math_output`_ +required for many output formats. For HTML, the `math_output`_ configuration setting (or the corresponding ``--math-output`` command line option) select between alternative output formats with different subsets of supported elements. If a writer does not @@ -1570,9 +1570,9 @@ Class elements. The "class" directive sets the `"classes"`_ attribute value on its content -or on the first immediately following non-comment element [#]_. For -details of the "classes" attribute, see `its entry`__ in `The Docutils -Document Tree`_. +or on the first immediately following [#]_ non-comment element [#]_. For +details of the "classes" attribute, see the `classes entry in The Docutils +Document Tree`__. The directive argument consists of one or more space-separated class names. The names are transformed to conform to the regular expression @@ -1621,6 +1621,26 @@ The text above is parsed and transformed into this doctree fragment:: Second paragraph. + +.. [#] This is also true, if the class directive is "nested" at the end of + an indented text block, for example:: + + .. note:: the class values set in this directive-block do not apply to + the note but the next paragraph. + + .. class:: special + + This is a paragraph with class value "special". + + This allows the "classification" of individual list items (except the + first, as a preceding class directive applies to the list as a whole):: + + * bullet list + + .. class:: classy item + + * second item, with class argument + .. [#] To set a "classes" attribute value on a block quote, the "class" directive must be followed by an empty comment:: diff --git a/docutils/docs/ref/rst/restructuredtext.txt b/docutils/docs/ref/rst/restructuredtext.txt index c205519e8..484a7c1f4 100644 --- a/docutils/docs/ref/rst/restructuredtext.txt +++ b/docutils/docs/ref/rst/restructuredtext.txt @@ -1551,7 +1551,10 @@ targets, directives, substitution definitions, and comments. Footnotes ````````` -Doctree elements: footnote, label. +Doctree elements: footnote_, label_. + +.. _footnote: ../doctree.html#footnote +.. _label: ../doctree.html#label Each footnote consists of an explicit markup start (".. "), a left square bracket, the footnote label, a right square bracket, and @@ -1748,7 +1751,9 @@ differently from footnotes. For example:: Hyperlink Targets ````````````````` -Doctree element: target. +Doctree element: target_. + +.. _target: ../doctree.html#target These are also called _`explicit hyperlink targets`, to differentiate them from `implicit hyperlink targets`_ defined below. @@ -1785,7 +1790,7 @@ indirect. 1. _`Internal hyperlink targets` have empty link blocks. They provide an end point allowing a hyperlink to connect one place to another within a document. An internal hyperlink target points to the - element following the target. For example:: + element following the target. [#]_ For example:: Clicking on this internal hyperlink will take us to the target_ below. @@ -1817,6 +1822,18 @@ indirect. An inline form of internal hyperlink target is available; see `Inline Internal Targets`_. + .. [#] Works also, if the internal hyperlink target is "nested" at the + end of an indented text block. This behaviour allows setting targets + to individual list items (except the first, as a preceding internal + target applies to the list as a whole):: + + * bullet list + + .. _`second item`: + + * second item, with hyperlink target. + + 2. _`External hyperlink targets` have an absolute or relative URI or email address in their link blocks. For example, take the following input:: @@ -2754,7 +2771,9 @@ reference names. Footnote References ------------------- -Doctree element: footnote_reference. +Doctree element: footnote_reference_. + +.. _footnote_reference: ../doctree.html#footnote-reference Start-string = "[", end-string = "]_". diff --git a/docutils/docutils/writers/html4css1/__init__.py b/docutils/docutils/writers/html4css1/__init__.py index 974480cab..5580a0c15 100644 --- a/docutils/docutils/writers/html4css1/__init__.py +++ b/docutils/docutils/writers/html4css1/__init__.py @@ -704,7 +704,13 @@ class HTMLTranslator(nodes.NodeVisitor): self.body.append('\n') def visit_definition_list_item(self, node): - pass + # pass class arguments, ids and names to definition term: + node.children[0]['classes'] = ( + node.get('classes', []) + node.children[0].get('classes', [])) + node.children[0]['ids'] = ( + node.get('ids', []) + node.children[0].get('ids', [])) + node.children[0]['names'] = ( + node.get('names', []) + node.children[0].get('names', [])) def depart_definition_list_item(self, node): pass diff --git a/docutils/test/test_writers/test_html4css1_misc.py b/docutils/test/test_writers/test_html4css1_misc.py index e61ded586..7a3dc0dea 100755 --- a/docutils/test/test_writers/test_html4css1_misc.py +++ b/docutils/test/test_writers/test_html4css1_misc.py @@ -31,6 +31,48 @@ class EncodingTestCase(DocutilsTestSupport.StandardTestCase): # xmlcharrefreplace handler is used. self.assertIn(b('EUR = €'), result) +class MovingArgsTestCase(DocutilsTestSupport.StandardTestCase): + + settings_overrides={'stylesheet_path': '', + # 'embed_stylesheet': False, + '_disable_config': True, + } + + def test_definition_list_item_classes(self): + # Do not drop class arguments for the definition list item. + # Pass them to to the term node instead. + data = """\ +first term: + fist def + + .. class:: for the second item + +second term: + second def +""" + result = core.publish_string(data, writer_name='html4css1', + settings_overrides=self.settings_overrides) + self.assertIn(b('
second term:
'), + result) + + def test_definition_list_item_name(self): + # Do not drop the "name" of the definition list item. + # Pass it to to the term node instead. + data = """\ +first term: + first def + + .. _second item: + +second term: + second def +""" + result = core.publish_string(data, writer_name='html4css1', + settings_overrides=self.settings_overrides) + self.assertIn(b('
second term:
'), + result) + + class SettingsTestCase(DocutilsTestSupport.StandardTestCase): data = 'test' -- 2.11.4.GIT