diff --git a/src/helpers.ts b/src/helpers.ts index 6be912be..071a42f1 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -146,7 +146,10 @@ export function trimTrailingBlankLines(str: string) { * keeps the folded label lower case, the form `def.tag` has always used. */ export function normalizeLabel(label: string) { - return label.toLowerCase().toUpperCase().toLowerCase(); + // 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(); } export function findClosingBracket(str: string, b: string) { diff --git a/test/specs/new/link_reference_label_whitespace.html b/test/specs/new/link_reference_label_whitespace.html new file mode 100644 index 00000000..f91f8e3e --- /dev/null +++ b/test/specs/new/link_reference_label_whitespace.html @@ -0,0 +1,3 @@ +

foo

+

bar

+

baz

diff --git a/test/specs/new/link_reference_label_whitespace.md b/test/specs/new/link_reference_label_whitespace.md new file mode 100644 index 00000000..10043b84 --- /dev/null +++ b/test/specs/new/link_reference_label_whitespace.md @@ -0,0 +1,9 @@ +[foo ] + +[ bar] + +[baz] + +[foo]: /foo +[bar]: /bar +[baz ]: /baz