Markdown Syntax Not Converted Within HTML Tags in markdown2
syntaxsurge opened this issue · 3 comments
Description
When using the markdown2
library to convert Markdown to HTML, I've noticed that Markdown syntax is not being converted inside HTML tags. Specifically, the bold syntax **text**
within <p>
tags is not converted to <strong>
HTML tags as expected. This issue seems to affect Markdown syntax within any HTML tag, not just paragraph tags.
Steps to Reproduce
- Use the
markdown2
library to convert a string that contains both HTML and Markdown syntax. For example, a string with paragraph tags<p>
containing Markdown bold syntax**
. - Observe the output, where the Markdown syntax within the HTML tags is not converted.
Expected Behavior
Markdown syntax within HTML tags should be converted to their respective HTML tags. For example, **text**
within <p>
tags should become <p><strong>text</strong></p>
.
Actual Behavior
The Markdown syntax within HTML tags remains unchanged in the output HTML. For example, **text**
within <p>
tags stays as <p>**text**</p>
.
Environment
- markdown2 version: 2.4.10
- Python version: 3.10.12
- Operating System: Linux Ubuntu
Additional Information
- This issue impacts the rendering of Markdown content in HTML environments where Markdown syntax is expected to be fully supported.
- A temporary workaround involves manually processing the HTML to replace Markdown syntax with the corresponding HTML tags, but this is not ideal for a comprehensive Markdown processor like
markdown2
.
Code to Reproduce
import markdown2
input_text = '''
<p>Here is some bold text in Markdown: **Bold Text** within HTML tags.</p>
'''
output_html = markdown2.markdown(input_text, extras=['tables', 'footnotes'])
print(output_html) # Expected: <p>Here is some bold text in Markdown: <strong>Bold Text</strong> within HTML tags.</p>
# Actual: <p>Here is some bold text in Markdown: Bold Text within HTML tags.</p>
Have you tried the markdown-in-html
extra?
Have you tried the
markdown-in-html
extra?
Thank you for suggesting the markdown-in-html
extra for markdown2
. I tried using it as you recommended, but it appears that this feature doesn't support the specific nesting of Markdown within HTML tags in my case. In my content, the Markdown syntax (like **bold text**) is directly within <p> tags, which seems to prevent markdown2
from processing it correctly. The documentation for markdown-in-html
indicates that the Markdown syntax should not be on the same line as the block-level HTML element, which is a constraint in my scenario as the string is constant and cannot be changed.
Do you have any other suggestions or workarounds that might help in this situation? Alternatively, are you aware of any other Markdown processors that might better handle this kind of nested Markdown within HTML? I appreciate your input and assistance on this.
The documentation for
markdown-in-html
indicates that the Markdown syntax should not be on the same line as the block-level HTML element
My bad, I didn't realise that this limitation existed. I've opened a PR to address this. Let me know if that addresses the use case.