mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Improve MD034/no-bare-urls range reporting (fixes #181).
This commit is contained in:
parent
dba6d4994b
commit
684416a902
4 changed files with 138 additions and 11 deletions
26
lib/md034.js
26
lib/md034.js
|
|
@ -2,27 +2,31 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorContext, bareUrlRe, filterTokens, rangeFromRegExp } =
|
||||
require("../helpers");
|
||||
const { addErrorContext, bareUrlRe, filterTokens } = require("../helpers");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD034", "no-bare-urls" ],
|
||||
"description": "Bare URL used",
|
||||
"tags": [ "links", "url" ],
|
||||
"function": function MD034(params, onError) {
|
||||
filterTokens(params, "inline", function forToken(token) {
|
||||
filterTokens(params, "inline", (token) => {
|
||||
let inLink = false;
|
||||
token.children.forEach(function forChild(child) {
|
||||
token.children.forEach((child) => {
|
||||
const { content, line, lineNumber, type } = child;
|
||||
let match = null;
|
||||
if (child.type === "link_open") {
|
||||
if (type === "link_open") {
|
||||
inLink = true;
|
||||
} else if (child.type === "link_close") {
|
||||
} else if (type === "link_close") {
|
||||
inLink = false;
|
||||
} else if ((child.type === "text") &&
|
||||
!inLink &&
|
||||
(match = bareUrlRe.exec(child.content))) {
|
||||
addErrorContext(onError, child.lineNumber, match[0], null,
|
||||
null, rangeFromRegExp(child.line, bareUrlRe));
|
||||
} else if ((type === "text") && !inLink &&
|
||||
(match = bareUrlRe.exec(content))) {
|
||||
const [ bareUrl ] = match;
|
||||
const index = line.indexOf(content);
|
||||
const range = (index === -1) ? null : [
|
||||
line.indexOf(content) + match.index + 1,
|
||||
bareUrl.length
|
||||
];
|
||||
addErrorContext(onError, lineNumber, bareUrl, null, null, range);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue