Menu

#134 listings having multiple labels are converted to invalid HTML

None
closed-fixed
nobody
None
5
2017-02-03
2016-10-07
No

The following document is converted to invalid HTML.
Input:

.. _label0:
.. _label1:


* list_item

Output:

<ul class="simple" id="label1">
<span id="label0"></span><li>list_item</li>
</ul>

The HTML writers generate empty span tags to create hyperlink targets if the listing node having multiple IDs.
But HTML expects listing elements (ul, ol and dl) have only li elements.

refs:

My patch fixes HTML writers both HTML4 and HTML5. With the patch, the document will be converted to following:

<span id="label0"></span><ul class="simple" id="label1">
<li>list_item</li>
</ul>

Thanks,

1 Attachments

Discussion

  • Günter Milde

    Günter Milde - 2016-10-11

    I suppose the patch could be made simpler by using the "empty" argument of starttag():

    - self.body.append(self.starttag(node, 'ul', **atts))
    + self.body.append(self.starttag(node, 'ul', empty=True, **atts))

    The comment/explanation inside starttag() should be updated to say
    "empty or list tag".

     
  • Takeshi KOMIYA

    Takeshi KOMIYA - 2016-10-12

    Thank you for reviewing! I missed the empty argument.
    I updated my patch using it.

     
  • Günter Milde

    Günter Milde - 2016-10-12

    Actually, this does not work, because of side-effects (creating an empty tag with closing
    like

    , say
    Instead, I suggest testing for "list-nodes" instead in starttag(). The html5-writer patch would become:

     --- __init__.py    (Revision 7969)
    +++ __init__.py (Arbeitskopie)
    @@ -431,8 +431,11 @@
                     # may be targets inside of references, but nested "a"
                     # elements aren't allowed in XHTML (even if they do
                     # not all have a "href" attribute).
    
    -                if empty:
    -                    # Empty tag.  Insert target right in front of element.
    +                if empty or isinstance(node,
    +                            (nodes.bullet_list, nodes.enumerated_list,
    +                             nodes.definition_list, nodes.field_list,
    +                             nodes.option_list, nodes.docinfo)):
    +                    # Insert target right in front of element.
                         prefix.append('<span id="%s"></span>' % id)
                     else:
                         # Non-empty tag.  Place the auxiliary <span> tag
    
     
  • Günter Milde

    Günter Milde - 2017-02-03
    • status: open --> closed-fixed
     
  • Günter Milde

    Günter Milde - 2017-02-03

    This is fixed in the repo. Thanks for reporting and patch.

     

Log in to post a comment.

MongoDB Logo MongoDB