Python-Markdown / markdown

A Python implementation of John Gruber’s Markdown with Extension support.
https://python-markdown.github.io/
BSD 3-Clause "New" or "Revised" License
3.81k stars 862 forks source link

Feature Request: Render contents that are inside `<details><summary>` block #1478

Closed zendern closed 2 months ago

zendern commented 2 months ago

Usecase

I have a markdown file that I want to transform to html using this library. When I have content that is inside of a <details> block it does not render correctly.

Example

Markdown File ``` ## Inside Details/Summary block (DOES NOT RENDER)
My summary | Operation | Types | Subtypes | Additional info | |----------------------------|---------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------| | **Prepare Solutions** | PREPARE_SOLUTIONS | - | - |
## Outside of details/summary block (RENDERS CORRECTLY) | Operation | Types | Subtypes | Additional info | |----------------------------|---------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------| | **Prepare Solutions** | PREPARE_SOLUTIONS | - | - | ```

Preview of the rendered Markdown in VSCode

Screenshot 2024-08-28 at 8 57 30 PM
Rendered Output by Python-Markdown ```html
My summary | Operation | Types | Subtypes | Additional info | |----------------------------|---------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------| | **Prepare Solutions** | PREPARE_SOLUTIONS | - | - |
Operation Types Subtypes Additional info
Prepare Solutions PREPARE_SOLUTIONS - -
```
Code to generate this html ```python import markdown # read a file to a string with open('example.md', 'r') as file: your_text_string = file.read() html = markdown.markdown(your_text_string, extensions=[ "admonition", "markdown.extensions.tables", "markdown.extensions.fenced_code", "pymdownx.magiclink", "pymdownx.tilde", "sane_lists", ],) print(html) ```

Attempted fixes

I thought maybe if i wrapped the table that is inside of the in a tag it might render it. Tried <div> and <p> but neither helped. From looking at the code i think its likely due to details being listed as a Block level element and its to not be touched so rendering never happens.

https://github.com/Python-Markdown/markdown/blob/fc74d69758ff288e26ff616c703b22ce5a02a68a/markdown/util.py#L47-L58

facelessuser commented 2 months ago

You are probably looking for https://python-markdown.github.io/extensions/md_in_html/ which allows you to parse Markdown in HTML block elements.

zender-vivodyne commented 2 months ago

💯 idk how i missed that one. But confirmed it does work as expected. Thank you @facelessuser. This can be closed.