diff --git a/index.compiler.spec.js b/index.compiler.spec.js index a7077c3c..bbb43de4 100644 --- a/index.compiler.spec.js +++ b/index.compiler.spec.js @@ -2972,6 +2972,67 @@ describe('footnotes', () => { +`); + }); + + it('should handle complex references', () => { + render(compiler(['foo[^referencé heré 123] bar', '', '[^referencé heré 123]: Baz baz'].join('\n'))); + + expect(root.innerHTML).toMatchInlineSnapshot(` + +
+

+ foo + + + referencé heré 123 + + + bar +

+ +
+ +`); + }); + + it('should handle conversion of multiple references into links', () => { + render(compiler(['foo[^abc] bar. baz[^def]', '', '[^abc]: Baz baz', '[^def]: Def'].join('\n'))); + + expect(root.innerHTML).toMatchInlineSnapshot(` + +
+

+ foo + + + abc + + + bar. baz + + + def + + +

+ +
+ `); }); diff --git a/index.js b/index.js index 60ae8b66..788ea79a 100644 --- a/index.js +++ b/index.js @@ -111,8 +111,8 @@ const CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/; const CODE_INLINE_R = /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/; const CONSECUTIVE_NEWLINE_R = /^(?:\n *)*\n/; const CR_NEWLINE_R = /\r\n?/g; -const FOOTNOTE_R = /^\[\^(.*)\](:.*)\n/; -const FOOTNOTE_REFERENCE_R = /^\[\^(.*)\]/; +const FOOTNOTE_R = /^\[\^([^\]]+)](:.*)\n/; +const FOOTNOTE_REFERENCE_R = /^\[\^([^\]]+)]/; const FORMFEED_R = /\f/g; const GFM_TASK_R = /^\s*?\[(x|\s)\]/; const HEADING_R = /^ *(#{1,6}) *([^\n]+)\n{0,2}/; @@ -966,7 +966,7 @@ export function compiler(markdown, options) { parse(capture /*, parse*/) { return { content: capture[1], - target: `#${capture[1]}`, + target: `#${options.slugify(capture[1])}`, }; }, react(node, output, state) { @@ -1565,7 +1565,7 @@ export function compiler(markdown, options) {