mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add MD052/reference-links-images and MD053/link-image-reference-definitions for reporting issues with link and image references (fixes #144, fixes #390, fixes #425, fixes #456).
This commit is contained in:
parent
2c947abf7b
commit
c5ca661b96
21 changed files with 1333 additions and 65 deletions
35
lib/md052.js
Normal file
35
lib/md052.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const { addError } = require("../helpers");
|
||||
const { referenceLinkImageData } = require("./cache");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD052", "reference-links-images" ],
|
||||
"description":
|
||||
"Reference links and images should use a label that is defined",
|
||||
"tags": [ "images", "links" ],
|
||||
"function": function MD052(params, onError) {
|
||||
const { lines } = params;
|
||||
const { references, definitions } = referenceLinkImageData();
|
||||
// Look for links/images that use an undefined link reference
|
||||
for (const reference of references.entries()) {
|
||||
const [ label, datas ] = reference;
|
||||
if (!definitions.has(label)) {
|
||||
for (const data of datas) {
|
||||
const [ lineIndex, index, length ] = data;
|
||||
// Context will be incomplete if reporting for a multi-line link
|
||||
const context = lines[lineIndex].slice(index, index + length);
|
||||
addError(
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
`Missing link or image reference definition: "${label}"`,
|
||||
context,
|
||||
[ index + 1, context.length ]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue