Skip to content

_ treated as <em> when it shouldn't #653

Closed

Description

Version: 8c74601

import markdown2

# Expected output:
# <p>_word1 <strong>strong</strong> word2._word3</p>
# Actual output:
# <p><em>word1 <strong>strong</strong> word2.</em>word3</p>
markdown_text = R"""
_word1 **strong** word2._word3
"""
print(markdown2.markdown(markdown_text))

Activity

  1. twavv commented on Nov 19, 2025

    @twavv

    This also happens with URLs which breaks them.

    import markdown2
    print(markdown2.markdown("https://docs.google.com/document/d/id_with_underscores/edit"))
    # <p>https://docs.google.com/document/d/id<em>with</em>underscores/edit</p>
    
  2. Crozzers commented on Nov 21, 2025

    @Crozzers
    Contributor

    This also happens with URLs which breaks them.

    Fixed with middle word em extra.


    Regarding the main issue, according to the original markdown spec this is a valid em.

    However, the original spec is vague and this example does look incorrect. The GFM spec covers this and has a comprehensive set of rules attached, but I don't see an easy way of implementing that.
    It would likely require completely re-writing how we process emphasis, doing away with the regex and going for a manual approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions