An autolink is a bare URL or email address in text, which Comrak turns into a link without any markup around it. CommonMark’s own autolinks need angle brackets around the address (<https://example.com>); this extension recognises addresses without them. Use autolinks when you want a bare address to be clickable.
<p>Visit <ahref="http://www.commonmark.org">www.commonmark.org</a>, read <ahref="https://spec.commonmark.org/">https://spec.commonmark.org/</a>, or write to <ahref="mailto:hello@example.com">hello@example.com</a>.</p>
Visit [www.commonmark.org](http://www.commonmark.org), read <https://spec.commonmark.org/>, or write to <hello@example.com>.
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">Visit </text><linkdestination="http://www.commonmark.org"title=""><textxml:space="preserve">www.commonmark.org</text></link><textxml:space="preserve">, read </text><linkdestination="https://spec.commonmark.org/"title=""><textxml:space="preserve">https://spec.commonmark.org/</text></link><textxml:space="preserve">, or write to </text><linkdestination="mailto:hello@example.com"title=""><textxml:space="preserve">hello@example.com</text></link><textxml:space="preserve">.</text></paragraph></document>
Syntax
Comrak recognises three kinds of autolink: www autolinks, URL autolinks, and email autolinks. It finds www and URL autolinks while it parses inline content, and email autolinks afterwards, in the text that remains.
Valid domains
A valid domain is one or more segments separated by periods (.). A segment is a sequence of characters that aren’t whitespace, punctuation, or symbols, except that underscores (_) and hyphens (-) are permitted. No underscore may appear in the last two segments:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.a_b.c.com"title=""><textxml:space="preserve">www.a_b.c.com</text></link><textxml:space="preserve"> www.a.b_c.com www.a_b.com</text></paragraph></document>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.bücher.de"title=""><textxml:space="preserve">www.bücher.de</text></link><textxml:space="preserve"></text><linkdestination="http://www.例え.jp"title=""><textxml:space="preserve">www.例え.jp</text></link></paragraph></document>
A domain with more than ten periods is valid even with underscores in its last two segments. This exception, inherited from cmark-gfm, avoids quadratic behaviour on long inputs:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.a.b.c.d.e.f.g.h.i.j.k_l.m_n"title=""><textxml:space="preserve">www.a.b.c.d.e.f.g.h.i.j.k_l.m_n</text></link></paragraph></document>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.commonmark.org"title=""><textxml:space="preserve">www.commonmark.org</text></link></paragraph></document>
<p>Visit <ahref="http://www.commonmark.org/help">www.commonmark.org/help</a> for more information.</p>
Visit [www.commonmark.org/help](http://www.commonmark.org/help) for more information.
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">Visit </text><linkdestination="http://www.commonmark.org/help"title=""><textxml:space="preserve">www.commonmark.org/help</text></link><textxml:space="preserve"> for more information.</text></paragraph></document>
www. must be lowercase, and the domain after it must contain a period. None of the following are www autolinks:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">WWW.commonmark.org www.com www.</text></paragraph></document>
A www autolink must begin at the start of a line, after whitespace, or after one of *, _, ~, or (:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">(</text><linkdestination="http://www.a.com"title=""><textxml:space="preserve">www.a.com</text></link><textxml:space="preserve">) </text><emph><linkdestination="http://www.b.com"title=""><textxml:space="preserve">www.b.com</text></link></emph><textxml:space="preserve"></text><emph><linkdestination="http://www.c.com"title=""><textxml:space="preserve">www.c.com</text></link></emph><textxml:space="preserve"> ~</text><linkdestination="http://www.d.com"title=""><textxml:space="preserve">www.d.com</text></link><textxml:space="preserve">~</text></paragraph></document>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">awww.a.com "www.b.com" .www.c.com</text></paragraph></document>
URL autolinks
A URL autolink is one of the schemes http://, https://, or ftp://, followed by a valid domain, followed by any further characters up to where the autolink ends. The scheme is case-insensitive. The domain needn’t contain a period, but its first character must not be punctuation.
<p><ahref="http://commonmark.org">http://commonmark.org</a></p><p>(Visit <ahref="https://encrypted.google.com/search?q=Markup+(business)">https://encrypted.google.com/search?q=Markup+(business)</a>)</p><p>Anonymous FTP is available at <ahref="ftp://foo.bar.baz">ftp://foo.bar.baz</a>.</p>
<http://commonmark.org>(Visit <https://encrypted.google.com/search?q=Markup+(business)>)
Anonymous FTP is available at <ftp://foo.bar.baz>.
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://commonmark.org"title=""><textxml:space="preserve">http://commonmark.org</text></link></paragraph><paragraph><textxml:space="preserve">(Visit </text><linkdestination="https://encrypted.google.com/search?q=Markup+(business)"title=""><textxml:space="preserve">https://encrypted.google.com/search?q=Markup+(business)</text></link><textxml:space="preserve">)</text></paragraph><paragraph><textxml:space="preserve">Anonymous FTP is available at </text><linkdestination="ftp://foo.bar.baz"title=""><textxml:space="preserve">ftp://foo.bar.baz</text></link><textxml:space="preserve">.</text></paragraph></document>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="HTTPS://example.com"title=""><textxml:space="preserve">HTTPS://example.com</text></link><textxml:space="preserve"></text><linkdestination="http://localhost:3000/admin"title=""><textxml:space="preserve">http://localhost:3000/admin</text></link></paragraph></document>
Other schemes aren’t recognised (but see Relaxed autolinks). None of the following are URL autolinks:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">1</text><linkdestination="http://a.com"title=""><textxml:space="preserve">http://a.com</text></link><textxml:space="preserve"> xhttp://a.com</text></paragraph></document>
one or more ASCII letters, digits, periods (.), hyphens (-), underscores (_), or plus signs (+);
an at sign (@); and,
one or more ASCII letters, digits, hyphens, underscores, and periods.
The part after the @ must contain at least one period, each period must be followed by an ASCII letter or digit, and the last character must be an ASCII letter.
The link’s destination is the address with mailto: in front:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="mailto:foo@bar.baz"title=""><textxml:space="preserve">foo@bar.baz</text></link></paragraph></document>
<p>hello@mail+xyz.example isn't valid, but <ahref="mailto:hello+xyz@mail.example">hello+xyz@mail.example</a> is.</p>
hello\@mail+xyz.example isn't valid, but <hello+xyz@mail.example> is.
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">hello@mail+xyz.example isn't valid, but </text><linkdestination="mailto:hello+xyz@mail.example"title=""><textxml:space="preserve">hello+xyz@mail.example</text></link><textxml:space="preserve"> is.</text></paragraph></document>
., -, and _ may appear on both sides of the @. A final . isn’t part of the address, and a final - or _ means there’s no email autolink:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="mailto:a.b-c_d@a.b"title=""><textxml:space="preserve">a.b-c_d@a.b</text></link></paragraph><paragraph><linkdestination="mailto:a.b-c_d@a.b"title=""><textxml:space="preserve">a.b-c_d@a.b</text></link><textxml:space="preserve">.</text></paragraph><paragraph><textxml:space="preserve">a.b-c_d@a.b-</text></paragraph><paragraph><textxml:space="preserve">a.b-c_d@a.b_</text></paragraph></document>
The address must end with a letter, and a second @ can’t follow the first:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">a@b.c1 a@</text><linkdestination="mailto:b@c.com"title=""><textxml:space="preserve">b@c.com</text></link></paragraph></document>
An email autolink may begin anywhere. The address starts just after the last character that can’t be part of it:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">☃</text><linkdestination="mailto:foo@bar.com"title=""><textxml:space="preserve">foo@bar.com</text></link><textxml:space="preserve"> x:</text><linkdestination="mailto:foo@bar.com"title=""><textxml:space="preserve">foo@bar.com</text></link></paragraph></document>
With mailto: or xmpp: directly before the address, the prefix is part of the autolink, and no mailto: is added. An xmpp: address may also have a resource after a slash (/):
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="mailto:foo@bar.com"title=""><textxml:space="preserve">mailto:foo@bar.com</text></link><textxml:space="preserve"></text><linkdestination="xmpp:foo@bar.com/home"title=""><textxml:space="preserve">xmpp:foo@bar.com/home</text></link><textxml:space="preserve"></text><linkdestination="mailto:foo@bar.com"title=""><textxml:space="preserve">foo@bar.com</text></link><textxml:space="preserve">/home</text></paragraph></document>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">foo@bar.com foo@bar.com</text></paragraph></document>
Where an autolink ends
A www or URL autolink extends up to the next whitespace character or <. Comrak then removes characters from its end, one at a time, until the autolink no longer ends with any of these:
one of ?, !, ., ,, :, *, _, ~, ', or ";
a ), if the autolink contains more ) than (;
a ;, together with any & and ASCII letters directly before it; and,
U+2069 POP DIRECTIONAL ISOLATE, after which Comrak removes nothing further.
Trailing punctuation isn’t part of the autolink, but the same characters may appear inside it:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">Visit </text><linkdestination="http://www.commonmark.org"title=""><textxml:space="preserve">www.commonmark.org</text></link><textxml:space="preserve">.</text></paragraph><paragraph><textxml:space="preserve">Visit </text><linkdestination="http://www.commonmark.org/a.b"title=""><textxml:space="preserve">www.commonmark.org/a.b</text></link><textxml:space="preserve">.</text></paragraph></document>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">"</text><linkdestination="https://a.com/x"title=""><textxml:space="preserve">https://a.com/x</text></link><textxml:space="preserve">", '</text><linkdestination="https://b.com/y"title=""><textxml:space="preserve">https://b.com/y</text></link><textxml:space="preserve">'!</text></paragraph></document>
An autolink keeps a ) that matches a ( within it, so it can sit inside parentheses:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.google.com/search?q=Markup+(business)"title=""><textxml:space="preserve">www.google.com/search?q=Markup+(business)</text></link></paragraph><paragraph><linkdestination="http://www.google.com/search?q=Markup+(business)"title=""><textxml:space="preserve">www.google.com/search?q=Markup+(business)</text></link><textxml:space="preserve">))</text></paragraph><paragraph><textxml:space="preserve">(</text><linkdestination="http://www.google.com/search?q=Markup+(business)"title=""><textxml:space="preserve">www.google.com/search?q=Markup+(business)</text></link><textxml:space="preserve">)</text></paragraph><paragraph><textxml:space="preserve">(</text><linkdestination="http://www.google.com/search?q=Markup+(business)"title=""><textxml:space="preserve">www.google.com/search?q=Markup+(business)</text></link></paragraph></document>
Only a final ) is checked, so unbalanced parentheses inside the autolink are kept:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.google.com/search?q=(business))+ok"title=""><textxml:space="preserve">www.google.com/search?q=(business))+ok</text></link></paragraph></document>
A final &, ASCII letters, and ; — something that looks like an entity reference — aren’t part of the autolink. A ; on its own is removed too:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.google.com/search?q=commonmark&hl=en"title=""><textxml:space="preserve">www.google.com/search?q=commonmark&hl=en</text></link></paragraph><paragraph><linkdestination="http://www.google.com/search?q=commonmark"title=""><textxml:space="preserve">www.google.com/search?q=commonmark</text></link><textxml:space="preserve">&hl;</text></paragraph><paragraph><linkdestination="http://www.google.com/search?q=commonmark&h1"title=""><textxml:space="preserve">www.google.com/search?q=commonmark&h1</text></link><textxml:space="preserve">;</text></paragraph></document>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.commonmark.org/he"title=""><textxml:space="preserve">www.commonmark.org/he</text></link><textxml:space="preserve"><lp</text></paragraph></document>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://example.com/[abc]]"title=""><textxml:space="preserve">http://example.com/[abc]]</text></link><textxml:space="preserve">...</text></paragraph></document>
Comrak checks the domain after removing these characters, so a trailing underscore doesn’t make the domain invalid:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.a.com"title=""><textxml:space="preserve">www.a.com</text></link><textxml:space="preserve">_ </text><strong><linkdestination="http://b.com"title=""><textxml:space="preserve">http://b.com</text></link></strong></paragraph></document>
The autolink’s text is the source text as written. Entity references and backslash escapes in it aren’t interpreted:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.a.com/?a=1&amp;b=2"title=""><textxml:space="preserve">www.a.com/?a=1&amp;b=2</text></link><textxml:space="preserve"></text><linkdestination="http://www.a.com/a\_b"title=""><textxml:space="preserve">www.a.com/a\_b</text></link></paragraph></document>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="/x"title=""><textxml:space="preserve">www.a.com</text></link><textxml:space="preserve"></text><imagedestination="/y.png"title=""><textxml:space="preserve">foo@bar.com</text></image><textxml:space="preserve"></text><codexml:space="preserve">http://a.com</code></paragraph></document>
Nor are they recognised inside brackets that don’t form a link (but see Relaxed autolinks):
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><emph><linkdestination="http://www.a.com"title=""><textxml:space="preserve">www.a.com</text></link></emph><textxml:space="preserve"></text><strong><linkdestination="http://b.com"title=""><textxml:space="preserve">http://b.com</text></link></strong><textxml:space="preserve"></text><emph><linkdestination="mailto:foo@bar.com"title=""><textxml:space="preserve">foo@bar.com</text></link></emph></paragraph></document>
Output
HTML output renders an autolink as an <a> element, just as it renders an inline link. The href is the destination described above, with the usual percent-encoding. The element’s content is the autolink’s text.
CommonMark output writes any link whose text equals its destination, ignoring a mailto: prefix, as a CommonMark autolink. URL and email autolinks therefore come out as <https://a.com> and <foo@bar.com>, but a www autolink comes out as an inline link, [www.a.com](http://www.a.com). With the extension enabled, CommonMark output escapes @ in other text (a\@b), to prevent reading the text back as an email autolink.
In XML output, an autolink is a link element with the destination in its destination attribute and an empty title.
In the AST, an autolink is a NodeValue::Link, like an inline link. Its NodeLink holds the destination and an empty title, and its only child is a text node. Nothing in the AST distinguishes an autolink from an inline link with the same text and destination.
<pdata-sourcepos="1:1-1:40">x <adata-sourcepos="1:3-1:11"href="http://www.a.com">www.a.com</a> y <adata-sourcepos="1:15-1:26"href="http://b.com">http://b.com</a> z <adata-sourcepos="1:30-1:40"href="mailto:foo@bar.com">foo@bar.com</a></p>
x [www.a.com](http://www.a.com) y <http://b.com> z <foo@bar.com>
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentsourcepos="1:1-1:40"xmlns="http://commonmark.org/xml/1.0"><paragraphsourcepos="1:1-1:40"><textsourcepos="1:1-1:2"xml:space="preserve">x </text><linksourcepos="1:3-1:11"destination="http://www.a.com"title=""><textsourcepos="1:3-1:11"xml:space="preserve">www.a.com</text></link><textsourcepos="1:12-1:14"xml:space="preserve"> y </text><linksourcepos="1:15-1:26"destination="http://b.com"title=""><textsourcepos="1:15-1:26"xml:space="preserve">http://b.com</text></link><textsourcepos="1:27-1:29"xml:space="preserve"> z </text><linksourcepos="1:30-1:40"destination="mailto:foo@bar.com"title=""><textsourcepos="1:30-1:40"xml:space="preserve">foo@bar.com</text></link></paragraph></document>
Options
Relaxed autolinks
With --relaxed-autolinks (parse.relaxed_autolinks), Comrak recognises autolinks in more places.
Autolinks are recognised inside brackets that don’t form a link:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">[</text><linkdestination="http://www.a.com"title=""><textxml:space="preserve">www.a.com</text></link><textxml:space="preserve">] [</text><linkdestination="http://b.com"title=""><textxml:space="preserve">http://b.com</text></link><textxml:space="preserve">] [</text><linkdestination="mailto:foo@bar.com"title=""><textxml:space="preserve">foo@bar.com</text></link><textxml:space="preserve">]</text></paragraph></document>
A URL autolink may use any scheme of ASCII letters, or none at all:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="smb:///Volumes/shared/foo.pdf"title=""><textxml:space="preserve">smb:///Volumes/shared/foo.pdf</text></link><textxml:space="preserve"></text><linkdestination="irc://irc.freenode.net/git"title=""><textxml:space="preserve">irc://irc.freenode.net/git</text></link><textxml:space="preserve"></text><linkdestination="rdar://localhost.com/blah"title=""><textxml:space="preserve">rdar://localhost.com/blah</text></link><textxml:space="preserve"></text><linkdestination="://a.com"title=""><textxml:space="preserve">://a.com</text></link></paragraph></document>
A www autolink’s domain needn’t contain a period, and a URL autolink’s domain may begin with punctuation, as in an IPv6 address:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.a"title=""><textxml:space="preserve">www.a</text></link><textxml:space="preserve"></text><linkdestination="http://[::1]:80/"title=""><textxml:space="preserve">http://[::1]:80/</text></link></paragraph></document>
The rule for a final ) also applies to ] and }. Comrak removes a final ] if the autolink contains more ] than [, and likewise for }:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">{</text><linkdestination="https://foo.com"title=""><textxml:space="preserve">https://foo.com</text></link><textxml:space="preserve">} </text><linkdestination="http://example.com/[abc]"title=""><textxml:space="preserve">http://example.com/[abc]</text></link><textxml:space="preserve">]...</text></paragraph></document>
Comrak takes a www or URL autolink that runs into ]( to be the text of a link, and doesn’t recognise it:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="url"title=""><textxml:space="preserve">http://foo.com/</text></link><textxml:space="preserve"></text><linkdestination="url"title=""><textxml:space="preserve">www.foo.com/</text></link></paragraph></document>
Interactions
--gfm enables autolinks, along with the other GitHub Flavored Markdown extensions:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><linkdestination="http://www.commonmark.org"title=""><textxml:space="preserve">www.commonmark.org</text></link></paragraph></document>
Autolinks work in table cells, and a cell’s pipes aren’t part of them:
| site | contact ||---|---||[www.a.com](http://www.a.com)|<foo@bar.com>|
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><table><table_header><table_cell><textxml:space="preserve">site</text></table_cell><table_cell><textxml:space="preserve">contact</text></table_cell></table_header><table_row><table_cell><linkdestination="http://www.a.com"title=""><textxml:space="preserve">www.a.com</text></link></table_cell><table_cell><linkdestination="mailto:foo@bar.com"title=""><textxml:space="preserve">foo@bar.com</text></link></table_cell></table_row></table></document>
With strikethrough, the tildes aren’t part of the autolink:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><strikethrough><linkdestination="http://www.a.com"title=""><textxml:space="preserve">www.a.com</text></link></strikethrough><textxml:space="preserve"></text><strikethrough><linkdestination="https://b.com"title=""><textxml:space="preserve">https://b.com</text></link></strikethrough></paragraph></document>
With task lists, an autolink straight after a task list item marker means the item isn’t a task list item:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><listtype="bullet"tasklist="true"tight="true"><taskitemcompleted="false"><paragraph><linkdestination="http://www.a.com"title=""><textxml:space="preserve">www.a.com</text></link></paragraph></taskitem><item><paragraph><textxml:space="preserve">[x]</text><linkdestination="https://b.com"title=""><textxml:space="preserve">https://b.com</text></link></paragraph></item></list></document>
With --smart, quotation marks around an autolink become curly, and aren’t part of it:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">‘</text><linkdestination="mailto:foo@bar.com"title=""><textxml:space="preserve">foo@bar.com</text></link><textxml:space="preserve">’ “</text><linkdestination="https://a.com"title=""><textxml:space="preserve">https://a.com</text></link><textxml:space="preserve">”</text></paragraph></document>
With wikilinks, a wikilink takes precedence over an autolink inside it:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><wikilinkdestination="www.a.com"embed="false"><textxml:space="preserve">www.a.com</text></wikilink><textxml:space="preserve"></text><wikilinkdestination="Docs"embed="false"><textxml:space="preserve">https://b.com</text></wikilink></paragraph></document>
Differences from cmark-gfm
cmark-gfm, the reference implementation of GitHub Flavored Markdown, uses the same autolink design as Comrak. It has no equivalent of Relaxed autolinks, and doesn’t support the wikilinks or footnotes extensions, so those examples aren’t comparable. On every other example above, the two implementations agree on HTML output, except that cmark-gfm:
accepts any valid domain after www., with or without a period, so www.com is a www autolink (example 7), and www.foo@bar.com is a www autolink rather than an email autolink;
checks the domain before removing trailing characters, so a trailing underscore makes a www or URL autolink invalid, even when the underscore closes emphasis (example 8, example 28);
recognises email autolinks formed by backslash escapes or entity references (example 20);
recognises email autolinks inside brackets that don’t form a link (example 31);
doesn’t remove a trailing U+2069 POP DIRECTIONAL ISOLATE (example 45); and,
Unicode isolates around a URL aren’t part of the autolink (#654). This example has an invisible U+2068 before the URL and an invisible U+2069 after it:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve"></text><linkdestination="https://www.example.com/"title=""><textxml:space="preserve">https://www.example.com/</text></link><textxml:space="preserve"></text></paragraph></document>
A relaxed email autolink in what looks like a footnote definition (#677):
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentxmlns="http://commonmark.org/xml/1.0"><paragraph><textxml:space="preserve">[^</text><linkdestination="mailto:a@b.c"title=""><textxml:space="preserve">a@b.c</text></link><softbreak/><textxml:space="preserve">A]:</text></paragraph></document>
Source positions of email autolinks in a table cell, around escaped pipes:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentsourcepos="1:1-2:5"xmlns="http://commonmark.org/xml/1.0"><tablesourcepos="1:1-2:5"><table_headersourcepos="1:1-1:21"><table_cellsourcepos="1:2-1:20"><linksourcepos="1:3-1:8"destination="mailto:a@b.cd"title=""><textsourcepos="1:3-1:8"xml:space="preserve">a@b.cd</text></link><textsourcepos="1:10-1:10"xml:space="preserve">|</text><linksourcepos="1:11-1:16"destination="mailto:e@f.gh"title=""><textsourcepos="1:11-1:16"xml:space="preserve">e@f.gh</text></link><textsourcepos="1:18-1:19"xml:space="preserve">|i</text></table_cell></table_header></table></document>
Source positions of an email autolink after smart punctuation:
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEdocument SYSTEM "CommonMark.dtd"><documentsourcepos="1:1-1:14"xmlns="http://commonmark.org/xml/1.0"><paragraphsourcepos="1:1-1:14"><textsourcepos="1:1-1:3"xml:space="preserve">a–</text><linksourcepos="1:4-1:14"destination="mailto:foo@bar.com"title=""><textsourcepos="1:4-1:14"xml:space="preserve">foo@bar.com</text></link></paragraph></document>