mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update MD011/no-reversed-links to remove RegExp negative lookbehind assertion which is not supported on Safari.
This commit is contained in:
parent
a8228ecd80
commit
e72b2ba985
2 changed files with 18 additions and 12 deletions
|
|
@ -2257,7 +2257,7 @@ module.exports = {
|
||||||
|
|
||||||
var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, forEachLine = _a.forEachLine, overlapsAnyRange = _a.overlapsAnyRange;
|
var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, forEachLine = _a.forEachLine, overlapsAnyRange = _a.overlapsAnyRange;
|
||||||
var _b = __webpack_require__(/*! ./cache */ "../lib/cache.js"), inlineCodeSpanRanges = _b.inlineCodeSpanRanges, lineMetadata = _b.lineMetadata;
|
var _b = __webpack_require__(/*! ./cache */ "../lib/cache.js"), inlineCodeSpanRanges = _b.inlineCodeSpanRanges, lineMetadata = _b.lineMetadata;
|
||||||
var reversedLinkRe = /(?<![\\\]])\(([^)]+)(?<!\\)\)\[([^\]^][^\]]*)(?<!\\)](?!\()/g;
|
var reversedLinkRe = /(^|[^\\])\(([^)]+)\)\[([^\]^][^\]]*)](?!\()/g;
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": ["MD011", "no-reversed-links"],
|
"names": ["MD011", "no-reversed-links"],
|
||||||
"description": "Reversed link syntax",
|
"description": "Reversed link syntax",
|
||||||
|
|
@ -2268,11 +2268,13 @@ module.exports = {
|
||||||
if (!inCode && !onFence) {
|
if (!inCode && !onFence) {
|
||||||
var match = null;
|
var match = null;
|
||||||
while ((match = reversedLinkRe.exec(line)) !== null) {
|
while ((match = reversedLinkRe.exec(line)) !== null) {
|
||||||
var reversedLink = match[0], linkText = match[1], linkDestination = match[2];
|
var reversedLink = match[0], preChar = match[1], linkText = match[2], linkDestination = match[3];
|
||||||
var index = match.index;
|
var index = match.index + preChar.length;
|
||||||
var length_1 = match[0].length;
|
var length_1 = match[0].length - preChar.length;
|
||||||
if (!overlapsAnyRange(exclusions, lineIndex, index, length_1)) {
|
if (!linkText.endsWith("\\") &&
|
||||||
addError(onError, lineIndex + 1, reversedLink, null, [index + 1, length_1], {
|
!linkDestination.endsWith("\\") &&
|
||||||
|
!overlapsAnyRange(exclusions, lineIndex, index, length_1)) {
|
||||||
|
addError(onError, lineIndex + 1, reversedLink.slice(preChar.length), null, [index + 1, length_1], {
|
||||||
"editColumn": index + 1,
|
"editColumn": index + 1,
|
||||||
"deleteCount": length_1,
|
"deleteCount": length_1,
|
||||||
"insertText": "[" + linkText + "](" + linkDestination + ")"
|
"insertText": "[" + linkText + "](" + linkDestination + ")"
|
||||||
|
|
|
||||||
16
lib/md011.js
16
lib/md011.js
|
|
@ -6,7 +6,7 @@ const { addError, forEachLine, overlapsAnyRange } = require("../helpers");
|
||||||
const { inlineCodeSpanRanges, lineMetadata } = require("./cache");
|
const { inlineCodeSpanRanges, lineMetadata } = require("./cache");
|
||||||
|
|
||||||
const reversedLinkRe =
|
const reversedLinkRe =
|
||||||
/(?<![\\\]])\(([^)]+)(?<!\\)\)\[([^\]^][^\]]*)(?<!\\)](?!\()/g;
|
/(^|[^\\])\(([^)]+)\)\[([^\]^][^\]]*)](?!\()/g;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "MD011", "no-reversed-links" ],
|
"names": [ "MD011", "no-reversed-links" ],
|
||||||
|
|
@ -18,14 +18,18 @@ module.exports = {
|
||||||
if (!inCode && !onFence) {
|
if (!inCode && !onFence) {
|
||||||
let match = null;
|
let match = null;
|
||||||
while ((match = reversedLinkRe.exec(line)) !== null) {
|
while ((match = reversedLinkRe.exec(line)) !== null) {
|
||||||
const [ reversedLink, linkText, linkDestination ] = match;
|
const [ reversedLink, preChar, linkText, linkDestination ] = match;
|
||||||
const index = match.index;
|
const index = match.index + preChar.length;
|
||||||
const length = match[0].length;
|
const length = match[0].length - preChar.length;
|
||||||
if (!overlapsAnyRange(exclusions, lineIndex, index, length)) {
|
if (
|
||||||
|
!linkText.endsWith("\\") &&
|
||||||
|
!linkDestination.endsWith("\\") &&
|
||||||
|
!overlapsAnyRange(exclusions, lineIndex, index, length)
|
||||||
|
) {
|
||||||
addError(
|
addError(
|
||||||
onError,
|
onError,
|
||||||
lineIndex + 1,
|
lineIndex + 1,
|
||||||
reversedLink,
|
reversedLink.slice(preChar.length),
|
||||||
null,
|
null,
|
||||||
[ index + 1, length ],
|
[ index + 1, length ],
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue