Skip to content

✨Allow plugins to register inline terminator characters#391

Merged
chrisjsewell merged 7 commits intomasterfrom
copilot/allow-plugins-register-terminators
May 6, 2026
Merged

✨Allow plugins to register inline terminator characters#391
chrisjsewell merged 7 commits intomasterfrom
copilot/allow-plugins-register-terminators

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

The inline text rule used a hardcoded, unexpandable set of terminator characters, forcing plugins that need to trigger on non-terminator characters (e.g. w for GFM www. autolinks) to resort to core-rule post-processing workarounds.

Changes

  • parser_inline.py: Moves the terminator set onto ParserInline as _terminator_chars (a set[str] seeded from _DEFAULT_TERMINATORS) with a pre-compiled terminator_re: re.Pattern[str] attribute. Exposes add_terminator_char(ch) to extend the set; the regex is rebuilt eagerly only when a genuinely new character is added, keeping zero per-call overhead in the hot path.

  • rules_inline/text.py: Drops the module-level _TerminatorChars set and @functools.cache-decorated factory. The text rule now reads state.md.inline.terminator_re directly.

  • docs/contributing.md: Updates the "Why is my inline rule not executed?" FAQ to document the new API.

Usage

def gfm_autolink_plugin(md: MarkdownIt) -> None:
    md.inline.add_terminator_char("w")
    md.inline.ruler.push("gfm_autolink_www", _www_rule)

Fully backward-compatible — the default terminator set is unchanged.

Copilot AI changed the title [WIP] Allow plugins to register inline terminator characters Allow plugins to register inline terminator characters May 4, 2026
Copilot AI requested a review from chrisjsewell May 4, 2026 21:17
Comment thread markdown_it/parser_inline.py Outdated
Copilot AI requested a review from chrisjsewell May 5, 2026 03:16
Comment thread markdown_it/parser_inline.py Outdated
Copilot AI requested a review from chrisjsewell May 5, 2026 03:40
@chrisjsewell chrisjsewell changed the title Allow plugins to register inline terminator characters ✨Allow plugins to register inline terminator characters May 5, 2026
@chrisjsewell chrisjsewell marked this pull request as ready for review May 5, 2026 06:52
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.84%. Comparing base (d4ea0ca) to head (422176a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #391   +/-   ##
=======================================
  Coverage   95.83%   95.84%           
=======================================
  Files          64       64           
  Lines        3481     3487    +6     
=======================================
+ Hits         3336     3342    +6     
  Misses        145      145           
Flag Coverage Δ
pytests 95.84% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chrisjsewell
Copy link
Copy Markdown
Member

@copilot fix pre-commit

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

@copilot fix pre-commit

Fixed in d5cf7ff — ruff corrected the import ordering and reformatted two expressions in parser_inline.py. All pre-commit checks now pass.

Copilot AI requested a review from chrisjsewell May 5, 2026 06:58
@chrisjsewell chrisjsewell merged commit df6fd36 into master May 6, 2026
15 checks passed
@chrisjsewell chrisjsewell deleted the copilot/allow-plugins-register-terminators branch May 6, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow plugins to register inline terminator characters

2 participants