diff --git a/README.md b/README.md index dabb609..919d226 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ marked: quotes: '“”‘’' modifyAnchors: 0 autolink: true + mangle: true sanitizeUrl: false headerIds: true lazyload: false @@ -53,6 +54,8 @@ marked: * Both double and single quotes substitution must be specified, otherwise it will be silently ignored. - **modifyAnchors** - Transform the anchorIds into lower case (`1`) or upper case (`2`). - **autolink** - Enable autolink for URLs. E.g. `https://hexo.io` will become `https://hexo.io`. +- **mangle** - Escape autolinked email address with HTML character references. + * This is to obscure email address from _basic_ crawler used by spam bot, while still readable to web browsers. - **sanitizeUrl** - Remove URLs that start with `javascript:`, `vbscript:` and `data:`. - **headerIds** - Insert header id, e.g. `
Contact: hi@example.com
\n'; + // https://stackoverflow.com/a/39243641 + const unescape = str => { + return str.replace(/&([^;]+);/g, (entity, entityCode) => { + const hex = entityCode.match(/^#x([\da-fA-F]+)$/); + const digit = entityCode.match(/^#(\d+)$/); + + if (hex) { + return String.fromCharCode(parseInt(hex[1], 16)); + } else if (digit) { + return String.fromCharCode(~~digit[1]); + } + return entity; + + }); + }; + + // mangle option only applies to autolinked email address + beforeEach(() => { hexo.config.marked.autolink = true; }); + + it('default', () => { + const result = r({text: body}); + + result.should.include(''); + unescape(result).should.eql(expected); + }); + + it('disabled', () => { + hexo.config.marked.mangle = false; + const result = r({text: body}); + + result.should.eql(expected); + }); + }); + it('should render link with title', () => { const body = [ '[text](http://link.com/ "a-title")',