Update MD054/link-image-style to add url_inline parameter (fixes #753).

This commit is contained in:
David Anson 2023-11-12 22:42:02 -08:00
parent 84333a5f08
commit b709a2f624
26 changed files with 347 additions and 39 deletions

View file

@ -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)}>`;
}