gfm.autolink – Turn URLs into links¶

The gfm.autolink module provides an extension that turns all raw URLs into marked-up links.

This is based on the web-only URL regex by John Gruber (public domain).

This regex seems to line up pretty closely with GitHub’s URL matching. Two cases were identified where they differ. In both cases, the regex were slightly modified to bring it in line with GitHub’s parsing:

  • GitHub accepts FTP-protocol URLs;
  • GitHub only accepts URLs with protocols or www., whereas Gruber’s regex accepts things like foo.com/bar.

Typical usage¶

import markdown
from gfm import AutolinkExtension

print(markdown.markdown("I love this http://example.org/ check it out",
                        extensions=[AutolinkExtension()]))
<p>I love this <a href="http://example.org/">http://example.org/</a> check it out</p>
class gfm.autolink.AutolinkExtension(*args, **kwargs)[source]¶

Bases: markdown.extensions.Extension

An extension that turns URLs into links.

extendMarkdown(md, md_globals)[source]¶

Add the various proccesors and patterns to the Markdown Instance.

This method must be overriden by every extension.

Keyword arguments:

  • md: The Markdown instance.
  • md_globals: Global variables in the markdown module namespace.
getConfig(key, default='')¶

Return a setting for the given key or an empty string.

getConfigInfo()¶

Return all config descriptions as a list of tuples.

getConfigs()¶

Return all configs settings as a dict.

setConfig(key, value)¶

Set a config setting for key with the given value.

setConfigs(items)¶

Set multiple config settings given a dict or list of tuples.

class gfm.autolink.AutolinkPattern(pattern, markdown_instance=None)[source]¶

Bases: markdown.inlinepatterns.Pattern

getCompiledRegExp()¶

Return a compiled regular expression.

handleMatch(m)[source]¶

Return a ElementTree element from the given match.

Subclasses should override this method.

Keyword arguments:

  • m: A re match object containing a match of the pattern.
type()¶

Return class name, to define pattern type

unescape(text)¶

Return unescaped text given text with an inline placeholder.

py-gfm

Navigation

  • gfm.autolink – Turn URLs into links
  • gfm.automail – Turn email addresses into links
  • gfm.hidden_hilite – Fenced code blocks with no highlighting
  • gfm.semi_sane_lists – GitHub-like list parsing
  • gfm.spaced_link – Links with optional whitespace
  • gfm.strikethrough – Strike-through support
  • gfm.tasklist – Task list support
  • gfm – Base module for GitHub-Flavored Markdown
  • mdx_gfm – Full extension for GFM (comments, issues)
  • mdx_partial_gfm – Partial extension for GFM (READMEs, wiki)

Related Topics

  • Documentation overview
    • <no title>
      • Previous: <no title>
      • Next: gfm.automail – Turn email addresses into links

Quick search

©2018, The Dart Team, Alexandre Macabies. | Powered by Sphinx 1.7.9 & Alabaster 0.7.8 | Page source