[docutils:feature-requests] #94 Should docutils whine about nesting simple body elements?

Günter Milde via Docutils-develop <[email protected]>
Newsgroups gmane.text.docutils.devel
Message-ID </p/docutils/feature-requests/94/0892d4c18a3b69b4305afbf09df87d59b7e9156d.feature-requests@docutils.p.sourceforge.net>
- **status**: open --> open-fixed
- **Group**:  --> Default
- **Comment**:

In Docutils 0.22 (since [r9732]), you can validate a  Document Tree element (`nodes.Element` instance) and its children by calling its `validate()` method. 
There is also a "transform" that checks a complete document after parsing and reports validation problems as WARNING system messages. It can be activated with the [validate](https://docutils.sourceforge.io/docs/user/config.html#validate) configuration setting.

The new "xml" parser validates the parsing result by default, so if you save the source
~~~
<paragraph classes="availability">
    <inline classes="xref std std-ref">Availability:</inline>
    Unix, not WASI.
    <paragraph>Content of the "availability" directive.</paragraph>
</paragraph>
~~~
to a file foo.xml, say, and run
    
    docutils --parser=xml --writer=pseudoxml foo.xml

the result is
~~~
<document source="/tmp/foo.xml">
    <paragraph classes="availability">
        
        <inline classes="xref std std-ref">
            Availability:
        
        Unix, not WASI.
        <paragraph>
            Content of the "availability" directive.
        
    <section classes="system-messages">
        <title>
            Docutils System Messages
        <system_message level="2" line="4" source="/tmp/foo.xml" type="WARNING">
            <paragraph>
                Element <paragraph classes="availability"> invalid:
                  Child element <paragraph> not allowed at this position.
~~~
The original example would also complain about the unknown node `<pending_xref>` as this is an extension by Sphinx.



---

**[feature-requests:#94] Should docutils whine about nesting simple body elements?**

**Status:** open-fixed
**Group:** Default
**Created:** Thu Feb 09, 2023 09:55 AM UTC by Julien Palard
**Last Updated:** Thu May 11, 2023 08:00 AM UTC
**Owner:** nobody


Context:

[This](https://github.com/python/cpython/blob/45fa12aec8f508c224a1521cfe3ae597f1026264/Doc/tools/extensions/pyspecific.py#L149) call to `nested_parse` adds a `Paragraph` node to a `Paragraph` node,  this look forbidden by [the doc](https://docutils.sourceforge.io/docs/ref/doctree.html#body-elements), and it also look to misbehave sphinx-side, when translating the document, where we completly loose the nested paragraph once translated.

It renders properly though when **not** translated.

The linked `nested_parse` returns:

```xml
<paragraph classes="availability">
    <pending_xref refdoc="index" refdomain="std" refexplicit="True" reftarget="availability" reftype="ref" refwarn="True">
        <inline classes="xref std std-ref">
            Availability
    : 
    Unix, not Emscripten, not WASI.
    <paragraph>
        Hello world I'm the content of the "availability" directive.
```

If it's really something that should not be done, maybe some kind of warning at build time could help debugging those issues?



---

Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/docutils/feature-requests/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/feature-requests/options.  Or, if this is a mailing list, you can unsubscribe from the mailing list.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.