mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Update MD051/link-fragments to add the ignored_pattern configuration parameter (fixes #547).
This commit is contained in:
parent
45932c7837
commit
02478d24cf
17 changed files with 297 additions and 4 deletions
8
lib/configuration-strict.d.ts
vendored
8
lib/configuration-strict.d.ts
vendored
|
|
@ -970,6 +970,10 @@ export interface ConfigurationStrict {
|
|||
* Ignore case of fragments
|
||||
*/
|
||||
ignore_case?: boolean;
|
||||
/**
|
||||
* Pattern for ignoring additional fragments
|
||||
*/
|
||||
ignored_pattern?: string;
|
||||
};
|
||||
/**
|
||||
* MD051/link-fragments : Link fragments should be valid : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md051.md
|
||||
|
|
@ -981,6 +985,10 @@ export interface ConfigurationStrict {
|
|||
* Ignore case of fragments
|
||||
*/
|
||||
ignore_case?: boolean;
|
||||
/**
|
||||
* Pattern for ignoring additional fragments
|
||||
*/
|
||||
ignored_pattern?: string;
|
||||
};
|
||||
/**
|
||||
* MD052/reference-links-images : Reference links and images should use a label that is defined : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md052.md
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ export default {
|
|||
"parser": "micromark",
|
||||
"function": function MD051(params, onError) {
|
||||
const ignoreCase = params.config.ignore_case || false;
|
||||
const ignoredPattern = params.config.ignored_pattern || "";
|
||||
const ignoredPatternRe = new RegExp(ignoredPattern || "^$");
|
||||
/** @type {Map<string, number>} */
|
||||
const fragments = new Map([ [ "#top", 0 ] ]);
|
||||
|
||||
|
|
@ -114,12 +116,14 @@ export default {
|
|||
for (const definition of definitions) {
|
||||
const { endColumn, startColumn } = definition;
|
||||
const text = unescapeStringTokenText(definition);
|
||||
const encodedText = `#${encodeURIComponent(text.slice(1))}`;
|
||||
const textSliceOne = text.slice(1);
|
||||
const encodedText = `#${encodeURIComponent(textSliceOne)}`;
|
||||
if (
|
||||
(text.length > 1) &&
|
||||
text.startsWith("#") &&
|
||||
!fragments.has(encodedText) &&
|
||||
!lineFragmentRe.test(encodedText)
|
||||
!lineFragmentRe.test(encodedText) &&
|
||||
!ignoredPatternRe.test(textSliceOne)
|
||||
) {
|
||||
let context = undefined;
|
||||
let range = undefined;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue