Skip to content

Emphasis compatibility regression in 3.11.1 when punctuation precedes the closing delimiter #1657

Closed

Description

@qu3vipon

Summary

After upgrading from Python-Markdown 3.11.0 to 3.11.1, emphasis is no longer rendered when its content ends with punctuation and the closing ** is immediately followed by ordinary text.

I traced the behavior change to commit 6f825aa753d672ec2d8ec5bc7b70d14b919d2fe1 in #1632. I understand from the discussion there that the punctuation-aware delimiter rules were deliberately added. This report asks whether the resulting loss of compatibility is intended, and whether there is an acceptable way to preserve the earlier behavior.

Minimal reproduction

import markdown

print(markdown.markdown("**단어(설명)**입니다."))

Actual output in 3.11.1:

<p>**단어(설명)**입니다.</p>

Expected output, matching 3.10.3 and 3.11.0:

<p><strong>단어(설명)</strong>입니다.</p>

Version comparison

The following results were reproduced with Python 3.14.0 using the source from each release tag and master at 2258b48e551d0df7b149ea9c33969bea7c7a0a2b, without extensions.

Input 3.10.3 3.11.0 3.11.1
**단어(설명)**입니다. Strong Strong Literal
**term(test)**suffix Strong Strong Literal
**用語(test)**です Strong Strong Literal
**术语(test)**是 Strong Strong Literal
**term(test)** suffix Strong Strong Strong
**term**suffix Strong Strong Strong

Here, “Strong” means the intended content is wrapped in <strong>, and “Literal” means the ** markers remain in the output.

The issue is not specific to Korean or parentheses. For example:

import markdown

print(markdown.markdown("**term.**suffix"))
print(markdown.markdown("**term。**suffix"))
print(markdown.markdown("**term😀**suffix"))

Actual output in 3.11.1:

<p>**term.**suffix</p>
<p>**term。**suffix</p>
<p>**term😀**suffix</p>

Expected output, matching 3.11.0:

<p><strong>term.</strong>suffix</p>
<p><strong>term。</strong>suffix</p>
<p><strong>term😀</strong>suffix</p>

Impact

In Korean, grammatical particles and endings are normally attached directly to the preceding expression. Emphasizing a term with a parenthetical explanation therefore naturally produces input such as **단어(설명)**입니다.. Requiring a space at that boundary changes how the sentence is written.

Existing documents that rendered emphasis before the upgrade now display literal Markdown markers. Similar constructions can occur in other languages, as the examples above show.

Questions

  • Is the loss of emphasis in these previously supported constructions an intended compatibility change?
  • Would you consider restoring the earlier behavior for these cases, or providing an opt-in compatibility setting or supported extension approach?

Activity

  1. facelessuser commented on Oct 14, 2026

    @facelessuser
    Collaborator

    For better or worse, this matches the CommonMark behavior as the new emphasis uses CommonMark punctuation rules. Escaping the parentheses allows it to work:

    >>> import markdown
    >>> text = r'**단어\(설명\)**입니다.'
    >>> markdown.markdown(text)
    '<p><strong>단어(설명)</strong>입니다.</p>'

    If this is a problem, we could make the punctuation rules optional.

  2. facelessuser commented on Oct 14, 2026

    @facelessuser
    Collaborator

    For more clarity, this is supposed to allow for more sane logic around punctuation.

    *(**test**) more text*

    So it would yield

    (test) more text

    <p>
      <em>
        (<strong>test
        </strong>) more text
      </em>
    </p>

    instead of

    ( test ) more text

    <p>
      <em>
        (
      </em><em> test
      </em><em> ) more text
      </em>
    </p>
  3. facelessuser commented on Oct 14, 2026

    @facelessuser
    Collaborator

    To be fair, in most English environments, I suspect these kinds of cases would rarely come up, but maybe not so much in some non-English languages.

  4. waylan commented on Oct 14, 2026

    @waylan
    Member

    I didn't really think about non-English contexts being different for this based on the fact that this is the behavior of Commonmark. Now that I know that, I'm wondering if perhaps we should revert that change in behavior and allow an extension to offer the Commonmark behavior.

  5. facelessuser commented on Oct 14, 2026

    @facelessuser
    Collaborator

    @waylan I'm okay with that. It was either to make the punctuation rules optional (even off by default) or pull them out entirely. When I proposed them, I was prepared to leave them out if asked.

  6. waylan commented on Oct 14, 2026

    @waylan
    Member

    Let's do that then. Your extension can offer the new behavior for those who want/need it and the default behavior can remain unchanged from 3.11 for punctuation.

    Sorry I didn't think that through completely before.

  7. added
    confirmedConfirmed bug report or approved feature request.
    and removed
    needs-decisionA decision needs to be made regarding request.
    on Oct 14, 2026
  8. facelessuser commented on Oct 14, 2026

    @facelessuser
    Collaborator

    I didn't think it through either, as I was coming from an English usage perspective.

    I'll create a PR that removes the punctuation rules, and BetterEm can be used to get full CommonMark behavior, though I'll probably allow punctuation in BetterEm to be toggled off if anyone wants to.

    Python Markdown, in that respect, can retain the old-school rules but still have the better handling for nesting.

  9. facelessuser commented on Oct 14, 2026

    @facelessuser
    Collaborator

    I've created the PR.

  10. qu3vipon commented on Oct 15, 2026

    @qu3vipon
    Author

    Thank you for the quick response and for taking this into consideration.

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

    confirmedConfirmed bug report or approved feature request.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions