Skip to content

Rewrite emphasis handling - #1632

Draft
facelessuser wants to merge 1 commit into
Python-Markdown:masterfrom
facelessuser:feature/new-emphasis
Draft

Rewrite emphasis handling#1632
facelessuser wants to merge 1 commit into
Python-Markdown:masterfrom
facelessuser:feature/new-emphasis

Conversation

@facelessuser

Copy link
Copy Markdown
Collaborator
  • This is a complete rewrite of how emphasis handling is done.
  • Drop use of multiple regex patterns in run in multiple passes and instead evaluate delimiters, nested or otherwise, and build up HTML elements.
  • Try to consume tokens as much as possible until a full element is constructed (with children if any).
  • If an outer set of tokens cannot be resolved, but one or more sub tokens can, render the first sub token span and cache the remaining ones for subsequent reentry and render those until the cache is exhausted.
  • Two tests results were updated to match new behavior.

Description

AI Assistance Disclosure

  • No AI tools were used in preparing this PR.
  • If AI tools were used, I have disclosed which ones, and fully reviewed and verified their output.

Checklist

  • This PR follows the contribution guidelines.
  • The code follows the Code Style Guide.
  • The commit message follows the Commit Message Style Guide.
  • I have added or updated relevant docs, including release notes if applicable which follow the [Documentation Style Guide](Documentation Style Guide).
  • I have added or updated relevant tests.
  • I have not requested, and will not request, an automated AI review for this PR.

- This is a complete rewrite of how emphasis handling is done.
- Drop use of multiple regex patterns in run in multiple passes and
  instead evaluate delimiters, nested or otherwise, and build up HTML
  elements.
- Try to consume tokens as much as possible until a full element is
  constructed (with children if any).
- If an outer set of tokens cannot be resolved, but one or more sub
  tokens can, render the first sub token span and cache the remaining
  ones for subsequent reentry and render those until the cache is
  exhausted.
- Two tests results were updated to match new behavior.
@facelessuser

Copy link
Copy Markdown
Collaborator Author

This is purposely a draft and is being made available for testing. More tests should be written, etc. For review.

The proposal is to first release this in Pymdown Extensions, and once vetted in the real world, make it the default approach, but I will let Python Markdown make the decision to release it before then if desired.

@waylan

waylan commented Sep 7, 2026

Copy link
Copy Markdown
Member

Awesome! I haven't had an opportunity to fully review the code, but the idea seems sound. The one thing that gives me pause is that we are reducing the number of inline processors to run. In itself, that is not a problem, but it may be that some third-party extensions are expecting to inject their processors between a few of the now-combined processors. I'm not certain if that will cause issues for those extensions or not. Therefore, my inclination is to consider this a backward incompatible change. Presumably the release notes should include a warning for third-party extension devs. I don't think there is any way we can gracefully make these changes through deprecations.

Interestingly, the change this relies on already was pushing the next release into at least a minor release. Adding this to the same release would be ideal from that perspective. But I also see the desire to test more thoroughly. I'm undecided about it for now.

@waylan waylan added the work-in-progress A partial solution. More changes will be coming. label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

work-in-progress A partial solution. More changes will be coming.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants