Menu

#322 reference treated as image (AssertionError)

closed-invalid
nobody
None
5
2020-03-03
2017-07-22
No

Greetings Docutils developers,

docutils 0.14rc2

.venv/lib/python3.6/site-packages/docutils/writers/_html_base.py", line 1321, in visit_reference
assert len(node) == 1 and isinstance(node[0], nodes.image)
AssertionError

If visit_reference in htmlbase.HTMLTranslator is visited and it iterates over a list item with reference data w/ no wrapper, this assertion can be triggered.

For instance, if overriding build_contents in docutils.transforms.Contents from:

entry = nodes.paragraph('', '', reference)
item = nodes.list_item('', entry)

to

item = nodes.list_item('', reference)

It will run an assertion as if the reference is an image.

Background: Trying to get the list items in table of contents to list as <ul><li>text</li></ul> without wrapping in paragraph tags like <ul><li><p>text</p></li></ul>.

It'd submit a patch myself but am not sure if I'd keep the original intended behavior that was meant for images (https://en.wikipedia.org/wiki/Wikipedia:Chesterton%27s_fence)

Discussion

  • Tony Narlock

    Tony Narlock - 2017-07-22
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -8,9 +8,9 @@
     AssertionError
     ~~~
    
    -If visit_reference in htmlbase.HTMLTranslator is visited and it iterates over a list item with reference data w/ no wrapper, this assertion can be triggered.
    +If `visit_reference` in `htmlbase.HTMLTranslator` is visited and it iterates over a list item with reference data w/ no wrapper, this assertion can be triggered.
    
    -For instance, if overriding build_contents in docutils.transforms.Contents from:
    +For instance, if overriding `build_contents` in `docutils.transforms.Contents` from:
    
     ~~~
     entry = nodes.paragraph('', '', reference)
    @@ -25,6 +25,6 @@
    
     It will run an assertion as if the reference is an image.
    
    -Background: Trying to get the list items in table of contents to list as <ul><li>text</li></ul> without wrapping in paragraph tags like <ul><li><p>text</p></li></ul>.
    +Background: Trying to get the list items in table of contents to list as `<ul><li>text</li></ul>` without wrapping in paragraph tags like `<ul><li><p>text</p></li></ul>`.
    
     It'd submit a patch myself but am not sure if I'd keep the original intended behavior that was meant for images (https://en.wikipedia.org/wiki/Wikipedia:Chesterton%27s_fence)
    
     
  • Günter Milde

    Günter Milde - 2017-08-04
    • status: open --> closed-invalid
     
  • Günter Milde

    Günter Milde - 2017-08-04

    The assertion is there to ensure the doctree is well-formed.

    References are inline elements (i.e. must be nested in a Text element, see docutils/docs/ref/doctree.html#inline-elements) with just one exception
    mentioned in docutils.dtd:

    <!ELEMENT reference %text.model;>

    If you want to strip the paragraph elements in list items, see the html4css1 writer which strips paragraphs in compact lists (you may need to tell it the list is to be considered compact). I recommend to keep the paragraphs and use CSS styling to set the margins, though (see writers/html5_polyglot/plain.css).

     

Log in to post a comment.