Skip to content

Commit

Permalink
Change helpers.getReferenceLinkImageData().shortcuts from Set to Map …
Browse files Browse the repository at this point in the history
…using the same schema as .references (fixes #685).
  • Loading branch information
DavidAnson committed Dec 23, 2022
1 parent f000a33 commit 86a4a7d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
21 changes: 12 additions & 9 deletions demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 86a4a7d

Please sign in to comment.