Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown Syntax Not Converted Within HTML Tags in markdown2 #546

Closed
syntaxsurge opened this issue Dec 9, 2023 · 3 comments · Fixed by #547
Closed

Markdown Syntax Not Converted Within HTML Tags in markdown2 #546

syntaxsurge opened this issue Dec 9, 2023 · 3 comments · Fixed by #547

Comments

@syntaxsurge
Copy link

syntaxsurge commented Dec 9, 2023

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

  1. 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 **.
  2. 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>

@Crozzers
Copy link
Contributor

Crozzers commented Dec 9, 2023

Have you tried the markdown-in-html extra?

@syntaxsurge
Copy link
Author

syntaxsurge commented Dec 9, 2023

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.

@Crozzers
Copy link
Contributor

Crozzers commented Dec 9, 2023

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.

nicholasserra added a commit that referenced this issue Dec 10, 2023
Update `markdown-in-html` extra to handle markdown on same line as HTML (#546)
sscherfke added a commit to sscherfke/nicegui that referenced this issue Feb 3, 2024
- The "^" specifier is often too restrictive for 0.* versions so I would
  not recommend to use it in these cases:
  https://python-poetry.org/docs/dependency-specification/
- Markdown2: The issue from 2.4.11 was fixed in 2.4.12:
  - zauberzeug#2154
  - trentm/python-markdown2#546
  - https://github.com/trentm/python-markdown2/blob/master/CHANGES.md#python-markdown2-2412
- Watchfiles: Doesn't look like v1 will introduce breaking changes:
  samuelcolvin/watchfiles#186
- python-multipart: "^0.06" is "==0.0.6" which is too strict and
  at this stage, any release can potentially add breaking changes
- aiofiles: Uses CalVer and 24.0.0 is as likely to introduce breaking
  changes as 23.2.0.
- httpx: It does not look like 1.0.0 will introduce breaking changes
  (if you already fixed any deprecation warnings).  Testing against the
  1.0.0beata0 is advisable, though.
  encode/httpx#3069
- ifaddr: Development is rather slow, package looks quite stable.
  I don't think that a 0.3.0 will add breaking changes and a 1.0 is not
  in sight.
- pytest-asyncio: Restriction to >=0.19,<0.20 seems unwanted and updates
  are needed for recent pytest versions
- pytest: Has there been a reason to not support pytest7?  pytest8
  currently breaks some plugins, but this should be fixed soon.

Fixes: zauberzeug#2485
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants