diff --git a/src/ReactParser.js b/src/ReactParser.js index baee24d..f4f5d74 100644 --- a/src/ReactParser.js +++ b/src/ReactParser.js @@ -14,6 +14,8 @@ class ReactParser { } parse(tokens) { + const { langPrefix } = this.options; + return tokens.map((token) => { switch (token.type) { case 'space': { @@ -50,7 +52,7 @@ class ReactParser { } case 'code': { - const lang = token.lang ? `${this.options.langPrefix}${token.lang}` : null; + const lang = token.lang ? `${langPrefix}${token.lang}` : null; return this.renderer.code(token.text, lang); } @@ -90,6 +92,8 @@ class ReactParser { } parseInline(tokens) { + const { baseURL, openLinksInNewTab } = this.options; + return tokens.map((token) => { switch (token.type) { case 'text': { @@ -121,12 +125,12 @@ class ReactParser { } case 'link': { - const href = joinBase(token.href, this.options.baseURL); - return this.renderer.link(href, token.text, this.options.openLinksInNewTab); + const href = joinBase(token.href, baseURL); + return this.renderer.link(href, this.parseInline(token.tokens), openLinksInNewTab); } case 'image': { - const href = joinBase(token.href, this.options.baseURL); + const href = joinBase(token.href, baseURL); return this.renderer.image(href, token.text, token.title); } diff --git a/tests/markdown.spec.js b/tests/markdown.spec.js index 0994979..d8a5c2f 100644 --- a/tests/markdown.spec.js +++ b/tests/markdown.spec.js @@ -87,13 +87,13 @@ const cases = [ }, { title: 'render unordered lists', - markdown: '- option 1\n- option 2', - html: '', + markdown: '- option-1\n- option-2', + html: '', }, { title: 'render ordered lists', - markdown: '1. option 1\n2. option 2', - html: '
  1. option 1
  2. option 2
', + markdown: '1. option-1\n2. option-2', + html: '
  1. option-1
  2. option-2
', }, { title: 'render codeblocks', @@ -147,8 +147,8 @@ const cases = [ }, { title: 'should render table', - markdown: '|CellHead|\n|--|\n|CellBody|', - html: '
CellHead
CellBody
', + markdown: '|Head|\n|--|\n|Body|', + html: '
Head
Body
', }, { title: 'should render br tag', @@ -166,6 +166,11 @@ const cases = [ markdown: '\n\n\n', html: '', }, + { + title: 'should parse images inside links', + markdown: '[![Tests](https://p.com/i.png)](https://p.com)', + html: '

Tests

', + }, ]; test.each(cases)('should $title', ({ markdown, html, props = null }) => {