mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD054/link-image-style to add url_inline parameter (fixes #753).
This commit is contained in:
parent
84333a5f08
commit
b709a2f624
26 changed files with 347 additions and 39 deletions
8
lib/configuration.d.ts
vendored
8
lib/configuration.d.ts
vendored
|
|
@ -1020,6 +1020,10 @@ export interface Configuration {
|
|||
* Allow shortcut reference links and images
|
||||
*/
|
||||
shortcut?: boolean;
|
||||
/**
|
||||
* Allow URLs as inline links
|
||||
*/
|
||||
url_inline?: boolean;
|
||||
};
|
||||
/**
|
||||
* MD054/link-image-style : Link and image style : https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md054.md
|
||||
|
|
@ -1047,6 +1051,10 @@ export interface Configuration {
|
|||
* Allow shortcut reference links and images
|
||||
*/
|
||||
shortcut?: boolean;
|
||||
/**
|
||||
* Allow URLs as inline links
|
||||
*/
|
||||
url_inline?: boolean;
|
||||
};
|
||||
/**
|
||||
* headings : MD001, MD003, MD018, MD019, MD020, MD021, MD022, MD023, MD024, MD025, MD026, MD036, MD041, MD043
|
||||
|
|
|
|||
13
lib/md054.js
13
lib/md054.js
|
|
@ -32,7 +32,8 @@ module.exports = {
|
|||
const full = (config.full === undefined) || !!config.full;
|
||||
const collapsed = (config.collapsed === undefined) || !!config.collapsed;
|
||||
const shortcut = (config.shortcut === undefined) || !!config.shortcut;
|
||||
if (autolink && inline && full && collapsed && shortcut) {
|
||||
const urlInline = (config.url_inline === undefined) || !!config.url_inline;
|
||||
if (autolink && inline && full && collapsed && shortcut && urlInline) {
|
||||
// Everything allowed, nothing to check
|
||||
return;
|
||||
}
|
||||
|
|
@ -62,7 +63,8 @@ module.exports = {
|
|||
getTokenTextByType(descendents, "resourceDestinationString");
|
||||
if (destination) {
|
||||
// link kind is an inline link
|
||||
isError = !inline;
|
||||
const title = getTokenTextByType(descendents, "resourceTitleString");
|
||||
isError = !inline || (!urlInline && autolink && !title && !image);
|
||||
} else {
|
||||
// link kind is a full/collapsed/shortcut reference link
|
||||
const isShortcut = !children.some((t) => t.type === "reference");
|
||||
|
|
@ -80,13 +82,16 @@ module.exports = {
|
|||
if (startLine === endLine) {
|
||||
range = [ startColumn, endColumn - startColumn ];
|
||||
let insertText = null;
|
||||
if (inline && label) {
|
||||
const canInline = (inline && label);
|
||||
const canAutolink = (autolink && !image && autolinkAble(destination));
|
||||
if (canInline && (urlInline || !canAutolink)) {
|
||||
// Most useful form
|
||||
const prefix = (image ? "!" : "");
|
||||
// @ts-ignore
|
||||
const escapedLabel = label.replace(/[[\]]/g, "\\$&");
|
||||
const escapedDestination = destination.replace(/[()]/g, "\\$&");
|
||||
insertText = `${prefix}[${escapedLabel}](${escapedDestination})`;
|
||||
} else if (autolink && !image && autolinkAble(destination)) {
|
||||
} else if (canAutolink) {
|
||||
// Simplest form
|
||||
insertText = `<${removeBackslashEscapes(destination)}>`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue