Skip to content

✨ Add GFM autolink and composite GFM plugins#135

Open
chrisjsewell wants to merge 3 commits intomasterfrom
gfm-plugin
Open

✨ Add GFM autolink and composite GFM plugins#135
chrisjsewell wants to merge 3 commits intomasterfrom
gfm-plugin

Conversation

@chrisjsewell
Copy link
Copy Markdown
Member

Summary

Adds two new plugins that require markdown-it-py >= 4.1.0:

gfm_autolink — GFM autolink literals

Implements the GFM autolinks extension
with three inline scanners:

  • www. URLs (trigger char: w, via add_terminator_char)
  • http:///https:///mailto:/xmpp: URLs (trigger char: :)
  • Bare email addresses (trigger char: @)

Matching logic is ported from the Rust
gfm_autolinks
crate. Covers GFM spec examples 622–635 plus additional edge cases
(trailing delimiters, emphasis integration, parentheses balancing, etc.).

gfm — Composite GFM plugin

A single-call plugin that enables a GFM-like configuration:

  • Tables (built-in)
  • Strikethrough with single and double tildes (built-in)
  • GFM autolinks (gfm_autolink)
  • Task lists (built-in)
  • Alerts (built-in)
  • Footnotes (footnote_plugin, inline=False)
  • Dollar math (optional, disabled by default)
  • Front matter (optional, disabled by default)

Tag filtering is noted as a TODO.

Other changes

  • tox.ini: test envs pin markdown-it-py>=4.1.0
  • pyproject.toml: added pytest-timeout to testing extras

References

Add two new plugins:

- `gfm_autolink`: GFM autolink literals (www, protocol, email)
  using the new `add_terminator_char` API from markdown-it-py 4.1.0
- `gfm`: Composite plugin enabling tables, strikethrough (single+double
  tilde), autolinks, task lists, alerts, and footnotes

Both require markdown-it-py >= 4.1.0.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 89.96764% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.68%. Comparing base (d11bdaf) to head (a2e265c).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
mdit_py_plugins/gfm_autolink/_match.py 84.67% 21 Missing ⚠️
mdit_py_plugins/gfm_autolink/index.py 94.36% 8 Missing ⚠️
mdit_py_plugins/gfm/__init__.py 92.85% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
- Coverage   92.80%   92.68%   -0.12%     
==========================================
  Files          31       38       +7     
  Lines        1835     2257     +422     
==========================================
+ Hits         1703     2092     +389     
- Misses        132      165      +33     
Flag Coverage Δ
pytests 92.68% <89.96%> (-0.12%) ⬇️

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 Author

chrisjsewell commented May 6, 2026

Review

Summary

This PR adds two new plugins:

  1. gfm_autolink — Implements the GFM autolink extension (bare www., http(s)://, mailto:, xmpp:, and bare email addresses). Ported from the Rust markdown_it_autolink crate.
  2. gfm — A composite plugin that enables a full GFM-like experience (tables, strikethrough, autolinks, task lists, alerts, footnotes, and optionally dollar math / front matter).

All 32 tests pass.


Positives

  • Clean port from the Rust crate with well-structured matching logic in _match.py
  • Good test coverage with fixtures matching GFM spec examples (622–634) plus edge cases
  • Composite gfm_plugin is a nice convenience API
  • Proper version gating (markdown-it-py >= 4.1.0) with helpful error messages
  • pytest-timeout addition is sensible for catching hangs

Issues / Suggestions

1. _isspace redundancy in _match.py (✅ fixed)

_SPACE_CHARS = frozenset(" \t\r\n\x00\x0b\x0c")

def _isspace(ch: str) -> bool:
    return ch in _SPACE_CHARS or ch == "\r" or ch == "\n"

\r and \n are already in _SPACE_CHARS, so the extra or checks are dead code. Should simplify to just return ch in _SPACE_CHARS.

2. gfm/__init__.py — docstring formatting (✅ fixed)

The docstring list has an oddly placed blank line between "Alerts" and "Footnotes" that breaks the list:

- Alerts (built-in, markdown-it-py >= 4.1.0)
- Footnotes (``[^label]`` references and definitions)
Optional extras:

Should be:

- Alerts (built-in, markdown-it-py >= 4.1.0)
- Footnotes (``[^label]`` references and definitions)

Optional extras:

3. gfm/__init__.pymd.options dict-style vs attribute-style

The composite plugin mixes dict-style (md.options["tasklists"] = True) and attribute-style access patterns. The test file test_gfm_autolink.py uses md.options.xhtmlOut = False while test_gfm.py uses md.options["xhtmlOut"] = False. These should be consistent — pick one style.

4. Missing __all__ in gfm/__init__.py

The gfm_autolink/__init__.py exports __all__, but gfm/__init__.py defines it. Actually gfm/__init__.py does have __all__ = ("gfm_plugin",) — that's fine.

5. Consider ReDoS safety

The _match.py functions use character-by-character scanning (no regex on user input for the heavy lifting), which is good. The single regex _PROTO_RE in index.py is anchored and operates on state.pending (bounded). Looks safe.

6. Minor: _autolink_delim could short-circuit

When link_end is 0 at the start, the while loop won't execute, but the initial for loop over data[:0] is a no-op too. Not a bug, just a nit.


Verdict

The implementation is solid and well-tested. The main actionable items are:

  1. Fix the _isspace redundancy
  2. Fix the docstring formatting

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.

1 participant