diff --git a/lib/renderer.js b/lib/renderer.js index c5e3137..ef26b74 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -1,8 +1,10 @@ 'use strict'; const marked = require('marked'); +const { escape } = require('marked/src/helpers'); const { encodeURL, slugize, stripHTML, url_for, isExternalLink } = require('hexo-util'); const MarkedRenderer = marked.Renderer; +const MarkedTokenizer = marked.Tokenizer; const anchorId = (str, transformOption) => { return slugize(str.trim(), {transform: transformOption}); @@ -39,9 +41,8 @@ class Renderer extends MarkedRenderer { return `${text}`; } - // Support AutoLink option link(href, title, text) { - const { autolink, external_link, sanitizeUrl } = this.options; + const { external_link, sanitizeUrl } = this.options; const { url: urlCfg } = this.hexo.config; if (sanitizeUrl) { @@ -49,9 +50,6 @@ class Renderer extends MarkedRenderer { href = ''; } } - if (!autolink && href === text && title == null) { - return href; - } let out = ` { const body = [ 'Great website http://hexo.io', '', - '[Hexo](http://hexo.io)' + 'A webpage www.example.com', + '', + '[Hexo](http://hexo.io)', + '', + '[http://lorem.com/foo/](http://lorem.com/foo/)', + '', + '' ].join('\n'); it('autolink enabled', () => { const result = r({text: body}); result.should.eql([ - '

Great website http://hexo.io

\n', - '

Hexo

\n' - ].join('')); + '

Great website http://hexo.io

', + '

A webpage www.example.com

', + '

Hexo

', + '

http://lorem.com/foo/

', + '

http://dolor.com

' + ].join('\n') + '\n'); }); it('autolink disabled', () => { @@ -182,9 +191,12 @@ describe('Marked renderer', () => { const result = r({text: body}); result.should.eql([ - '

Great website http://hexo.io

\n', - '

Hexo

\n' - ].join('')); + '

Great website http://hexo.io

', + '

A webpage www.example.com

', + '

Hexo

', + '

http://lorem.com/foo/

', + '

http://dolor.com

' + ].join('\n') + '\n'); }); });