Module

plugins.autolinks

Autolinks plugin for Patitas.

Enables GFM extended autolinks: bare URLs,www.links, and bare email addresses are turned into links inside ordinary inline text. This implements the GFM "Autolinks (extension)" rules: https://github.github.com/gfm/#autolinks-extension-

>>> from patitas import Markdown
>>> Markdown(plugins=["autolinks"])("Visit https://example.com now")
'<p>Visit <a href="https://example.com">https://example.com</a> now</p>\n'
>>> Markdown(plugins=["autolinks"])("See www.example.com")
'<p>See <a href="http://www.example.com">www.example.com</a></p>\n'
>>> Markdown(plugins=["autolinks"])("Mail foo@example.com")
'<p>Mail <a href="mailto:foo@example.com">foo@example.com</a></p>\n'

Recognized forms (only when this plugin is enabled):

  • bare URLs:http://example.com, https://example.com
  • www links:www.example.com (rendered href gets http://prepended;
    the link text keeps the original ``www.`` text)
    
  • bare emails:user@example.com (href mailto:...)

Rules applied (per the GFM extension):

  • An autolink is recognized only at a left boundary: start-of-line/text, after whitespace, or after one of* _ ~ (.
  • A URL/www. body runs until whitespace or <, so characters that are otherwise inline-special (& ~ $ _ * [ ! {) are kept as part of the link. This means real-world URLs with query separators (?a=1&b=2), ~user paths, andFoo_(bar)slugs link in full.
  • Trailing punctuation (? ! . , : * _ ~) is excluded from the link. A trailing) is excluded when there are more ) than (in the match. A trailing entity reference (&...;) is stripped.
  • The authority must contain at least one.and no spaces.

CommonMark angle-bracket autolinks work without this plugin:

>>> Markdown()("Visit <https://example.com>")
'<p>Visit <a href="https://example.com">https://example.com</a></p>\n'

Precedence (GFM: code spans > autolinks > emphasis):

  • A backtick ends a URL body so a code span keeps its higher CommonMark/GFM precedence (http://a.com`code` does not swallow the code span).
  • An_inside an email local part is recognized as part of the address before emphasis tokenization, so e.g.a_b@example.com links in full. (* and~ are not valid email-local-part characters, so only _matters.)

Thread Safety:

This plugin is stateless and thread-safe.

Classes

AutolinksPlugin 1
Plugin enabling automatic (GFM extended) URL and email linking. Enabling via ``Markdown(plugins=["…

Plugin enabling automatic (GFM extended) URL and email linking.

Enabling viaMarkdown(plugins=["autolinks"])sets ParseConfig.autolinks_enabled, which the inline tokenizer consults to scan plain-text runs for bare URLs,www.links, and emails. CommonMark angle-bracket autolinks<https://...>already work without this plugin.

Methods

name 0 str
property
def name(self) -> str
Returns
str