3 var uri = require('../util/enclose-uri');
4 var title = require('../util/enclose-title');
8 /* Expression for a protocol:
9 * http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax */
10 var PROTOCOL = /^[a-z][a-z+.-]+:\/?/i;
14 * When no title exists, the compiled `children` equal
15 * `url`, and `url` starts with a protocol, an auto
18 * <http://example.com>
20 * Otherwise, is smart about enclosing `url` (see
21 * `encloseURI()`) and `title` (see `encloseTitle()`).
23 * [foo](<foo at bar dot com> 'An "example" e-mail')
25 * Supports named entities in the `url` and `title` when
26 * in `settings.encode` mode. */
29 var content = self.encode(node.url || '', node);
30 var exit = self.enterLink();
31 var escaped = self.encode(self.escape(node.url || '', node));
32 var value = self.all(node).join('');
38 PROTOCOL.test(content) &&
39 (escaped === value || escaped === 'mailto:' + value)
41 /* Backslash escapes do not work in autolinks,
42 * so we do not escape. */
43 return uri(self.encode(node.url), true);
46 content = uri(content);
49 content += ' ' + title(self.encode(self.escape(node.title, node), node));
52 return '[' + value + '](' + content + ')';