diff --git a/src/index.js b/src/index.js index 3938c5c..8a909b2 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 || {}, diff --git a/test/index.js b/test/index.js index 5262b16..d4aad91 100644 --- a/test/index.js +++ b/test/index.js @@ -151,6 +151,17 @@ describe('snarkdown()', () => { }); }); + describe('html', () => { + it('should not parse inside tags', () => { + expect(snarkdown('
')).to.equal(''); + expect(snarkdown('a')).to.equal('a'); + }); + + it('should parse outside HTML tags', () => { + expect(snarkdown('**a**')).to.equal('a'); + }); + }); + describe('edge cases', () => { it('should close unclosed tags', () => { expect(snarkdown('*foo')).to.equal('foo');