diff --git a/src/index.js b/src/index.js index 3938c5c..81d4714 100644 --- a/src/index.js +++ b/src/index.js @@ -24,7 +24,7 @@ function encodeAttr(str) { /** Parse Markdown into an HTML String. */ export default function parse(md, prevLinks) { - let tokenizer = /((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)/gm, + let tokenizer = /((?:^|\n+)(?:\n---+|\* \*(?: \*)+)\n)|(?:^``` *(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:!\[([^\]]*?)\]\(([^)]+?)\))|(\[)|(\](?:\(([^)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,6})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*]|~~)|(?:<([^>]+?)>)/gm, context = [], out = '', links = prevLinks || {}, @@ -85,6 +85,9 @@ export default function parse(md, prevLinks) { out = out.replace('', ``); chunk = flush() + ''; } + else if (token[18]) { + chunk = `${encodeAttr(token[18])}`; + } else if (token[9]) { chunk = ''; } diff --git a/test/index.js b/test/index.js index 5262b16..6b1513f 100644 --- a/test/index.js +++ b/test/index.js @@ -49,6 +49,10 @@ describe('snarkdown()', () => { expect(snarkdown('[Snarkdown](http://github.com/developit/snarkdown)')).to.equal('Snarkdown'); }); + it('parses link by angle bracket syntax', () => { + expect(snarkdown('')).to.equal('https://github.com'); + }); + it('parses anchor links', () => { expect(snarkdown('[Example](#example)')).to.equal('Example'); });