From 86a4a7de790fa5d07a387dd3261ba651940522aa Mon Sep 17 00:00:00 2001 From: David Anson Date: Fri, 23 Dec 2022 00:41:11 +0000 Subject: [PATCH] Change helpers.getReferenceLinkImageData().shortcuts from Set to Map using the same schema as .references (fixes #685). --- demo/markdownlint-browser.js | 21 ++++++++++++--------- helpers/helpers.js | 21 ++++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 5db887788..32ab3ade8 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -792,7 +792,7 @@ module.exports.emphasisMarkersInContent = emphasisMarkersInContent; function getReferenceLinkImageData(lineMetadata) { // Initialize return values const references = new Map(); - const shortcuts = new Set(); + const shortcuts = new Map(); const definitions = new Map(); const duplicateDefinitions = []; const definitionLineIndices = []; @@ -882,20 +882,23 @@ function getReferenceLinkImageData(lineMetadata) { } const referenceIndex = referenceindex + (topLevel ? -lineOffsets[lineIndex] : contentIndex); + const referenceDatum = [ + lineIndex, + referenceIndex, + matchString.length, + matchText.length, + (matchLabel || "").length + ]; if (shortcutLink) { // Track separately due to ambiguity in "text [text] text" - shortcuts.add(label); + const shortcutData = shortcuts.get(label) || []; + shortcutData.push(referenceDatum); + shortcuts.set(label, shortcutData); } else { // Track reference and location const referenceData = references.get(label) || []; - referenceData.push([ - lineIndex, - referenceIndex, - matchString.length, - matchText.length, - matchLabel.length - ]); + referenceData.push(referenceDatum); references.set(label, referenceData); } // Check for links embedded in brackets diff --git a/helpers/helpers.js b/helpers/helpers.js index 639ed2468..ae416e7f3 100644 --- a/helpers/helpers.js +++ b/helpers/helpers.js @@ -824,7 +824,7 @@ module.exports.emphasisMarkersInContent = emphasisMarkersInContent; function getReferenceLinkImageData(lineMetadata) { // Initialize return values const references = new Map(); - const shortcuts = new Set(); + const shortcuts = new Map(); const definitions = new Map(); const duplicateDefinitions = []; const definitionLineIndices = []; @@ -920,19 +920,22 @@ function getReferenceLinkImageData(lineMetadata) { } const referenceIndex = referenceindex + (topLevel ? -lineOffsets[lineIndex] : contentIndex); + const referenceDatum = [ + lineIndex, + referenceIndex, + matchString.length, + matchText.length, + (matchLabel || "").length + ]; if (shortcutLink) { // Track separately due to ambiguity in "text [text] text" - shortcuts.add(label); + const shortcutData = shortcuts.get(label) || []; + shortcutData.push(referenceDatum); + shortcuts.set(label, shortcutData); } else { // Track reference and location const referenceData = references.get(label) || []; - referenceData.push([ - lineIndex, - referenceIndex, - matchString.length, - matchText.length, - matchLabel.length - ]); + referenceData.push(referenceDatum); references.set(label, referenceData); } // Check for links embedded in brackets