executablebooks / MyST-Parser

An extended commonmark compliant parser, with bridges to docutils/sphinx
https://myst-parser.readthedocs.io
MIT License
708 stars 189 forks source link

no syntax to create line_block (hardbreak creates paragraph with raw linebreaks) #899

Closed eudoxos closed 3 months ago

eudoxos commented 3 months ago

What version of myst-parser are you using?

2.0.0

What version dependencies are you using?

docutils==0.20.1 sphinx==7.2.6

What operating system are you using?

Linux

Describe the Bug

MyST parser does not have proper syntax for line-block and emulates line-block by creating paragraph with hardbreaks (indicated by \ followed by linebreak). This introduces incompatibility in some (perhaps uncommon, but valid) cases. One of them is table with line-block:

# Test text block inside list-table

## list-table

```{list-table}

* - A1
  - B1 \
    in \
    3 lines 
* - A2
  - B2

list-table via eval-rst


.. list-table::

   * - A1
     - | B1
       | in
       | 3 lines
   * - A2
     - B2

The first table will be rendered incorrectly (as the B1 cell is a `paragraph` node with newlines  inserted as raw latex `\\` which has a different meaning inside table; whereas RST will process `line_block` node inside table with `line`s correctly).

![image](https://github.com/executablebooks/MyST-Parser/assets/1029876/1b524396-6531-4c6f-823a-e00b96d3922f)

![image](https://github.com/executablebooks/MyST-Parser/assets/1029876/eaadcf05-96ce-4d62-9907-008be50dc908)

The pseudoXML is here:
Test text block inside list-table <section ids="list-table" names="list-table"> <title> list-table <table> <tgroup cols="2"> <colspec colwidth="50"> <colspec colwidth="50"> <tbody> <row> <entry> <paragraph> A1 <entry> <paragraph> B1 <raw format="html" xml:space="preserve"> <br /> <raw format="latex" xml:space="preserve"> \\ in <raw format="html" xml:space="preserve"> <br /> <raw format="latex" xml:space="preserve"> \\ 3 lines <row> <entry> <paragraph> A2 <entry> <paragraph> B2 <section ids="list-table-via-eval-rst" names="list-table\ via\ eval-rst"> <title> list-table via eval-rst <table> <tgroup cols="2"> <colspec colwidth="50"> <colspec colwidth="50"> <tbody> <row> <entry> <paragraph> A1 <entry> <line_block> <line> B1 <line> in <line> 3 lines <row> <entry> <paragraph> A2 <entry> <paragraph> B2 ``` ### Expected Behavior (proposed behavior:) paragraph with hardbreaks and no softbreaks would be converted to `line_block`. Paragraph mixing hardbreaks and softbreaks would trigger warning. Paragraphs with softbreak only are just paragraphs. Or alternatively, document another way of creating `line_block` in MyST (I did not find one). ### To Reproduce Compile the above source (saved as `index.md`) with this minimal `conf.py`: ```py project="test" extensions=['myst_parser'] ``` </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/chrisjsewell"><img src="https://avatars.githubusercontent.com/u/2997570?v=4" />chrisjsewell</a> commented <strong> 3 months ago</strong> </div> <div class="markdown-body"> <p>I believe #900 closes this 😄 see updated <a href="https://myst-parser.readthedocs.io/en/latest/syntax/typography.html#line-breaks">https://myst-parser.readthedocs.io/en/latest/syntax/typography.html#line-breaks</a> </p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/eudoxos"><img src="https://avatars.githubusercontent.com/u/1029876?v=4" />eudoxos</a> commented <strong> 3 months ago</strong> </div> <div class="markdown-body"> <p>Oh, quite a co-incidence in time :) Can one use the new <code>line-block</code> directive inside a <code>list-table</code> item? I am not sure.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/eudoxos"><img src="https://avatars.githubusercontent.com/u/1029876?v=4" />eudoxos</a> commented <strong> 3 months ago</strong> </div> <div class="markdown-body"> <p>Related: #877 (paragraph with raw breaks does not work with a custom builder)</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/chrisjsewell"><img src="https://avatars.githubusercontent.com/u/2997570?v=4" />chrisjsewell</a> commented <strong> 3 months ago</strong> </div> <div class="markdown-body"> <blockquote> <p>Oh, quite a co-incidence in time :) </p> </blockquote> <p>If by coincidence, you mean I saw this issue and then fixed it 😄</p> <blockquote> <p>Can one use the new line-block directive inside a list-table item?</p> </blockquote> <p>yes you can 👍 </p> <p>I'll close this as fixed, but feel free to re-open or open a new issue, if there is anything else</p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>