diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 6deb91f9..3ae62ad8 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -614,7 +614,7 @@ export class _Tokenizer { return; } - const tag = normalizeLabel(cap[1]).replace(this.rules.other.multipleSpaceGlobal, ' '); + const tag = normalizeLabel(cap[1]); const href = cap[2] ? cap[2].replace(this.rules.other.hrefBrackets, '$1').replace(this.rules.inline.anyPunctuation, '$1') : ''; const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline.anyPunctuation, '$1') : cap[3]; return { @@ -857,8 +857,7 @@ export class _Tokenizer { return; } - const linkString = (cap[2] || cap[1]).replace(this.rules.other.multipleSpaceGlobal, ' '); - const link = links[normalizeLabel(linkString)]; + const link = links[normalizeLabel(cap[2] || cap[1])]; if (!link) { const text = cap[0].charAt(0); return { diff --git a/src/helpers.ts b/src/helpers.ts index 49b38693..68105ca8 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -155,9 +155,10 @@ export function trimTrailingBlankLines(str: string) { */ export function normalizeLabel(label: string) { // The spec also asks for leading and trailing spaces, tabs and line endings - // to be stripped. Doing it here keeps every call site in agreement: the - // definition and the reference have to normalize to the same key. - return label.trim().toLowerCase().toUpperCase().toLowerCase(); + // to be stripped, and for internal runs of them to collapse to one space. + // Doing it here keeps every call site in agreement: the definition and the + // reference have to normalize to the same key. + return label.trim().replace(other.multipleSpaceGlobal, ' ').toLowerCase().toUpperCase().toLowerCase(); } export function findClosingBracket(str: string, b: string) { diff --git a/test/specs/new/em_and_reflinks_whitespace.html b/test/specs/new/em_and_reflinks_whitespace.html new file mode 100644 index 00000000..1969bb8d --- /dev/null +++ b/test/specs/new/em_and_reflinks_whitespace.html @@ -0,0 +1,5 @@ +

*foo*

+

*foo*

+

*my ref*

+

*my +ref*

diff --git a/test/specs/new/em_and_reflinks_whitespace.md b/test/specs/new/em_and_reflinks_whitespace.md new file mode 100644 index 00000000..d19d31e0 --- /dev/null +++ b/test/specs/new/em_and_reflinks_whitespace.md @@ -0,0 +1,13 @@ +*[foo*][my ref] + +*[foo*][my +ref] + +*[my ref*] + +*[my +ref*] + +[my ref]: /uri + +[my ref*]: /uri