python-markdownify icon indicating copy to clipboard operation
python-markdownify copied to clipboard

heading and list item not converted well

Open caseykhuc opened this issue 2 years ago • 1 comments

Example HTML:

<ol>
   <h2>
      <li>Test heading</li>
   </h2>
   <h2>
      <li>Test heading 2</li>
   </h2>
</ol>

The expected rendering result should be like below: image

However, with the converted markdown, headings just disappear:


## 
- Test heading


## 
- Test heading 2



image

caseykhuc avatar Oct 19 '23 09:10 caseykhuc

The provided example is not valid HTML. Per the HTML5 specifications <ol>'s may only contain <li>'s or other <ol> or <ul>'s . https://www.w3.org/TR/2012/WD-html-markup-20120329/ol.html https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol

Using correct HTML structure, along with heading_style=ATX will give you the desired output

<ol>
   <li>
      <h2>Test heading</h2>
   </li>
   <li>
      <h2>Test heading 2</h2>
   </li>
</ol>
1. ## Test heading
2. ## Test heading 2

fogx avatar Feb 22 '24 15:02 fogx