mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +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
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