mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Reimplement MD034/no-bare-urls using micromark tokens (fixes #707).
This commit is contained in:
parent
64159fa456
commit
b990b3ea77
22 changed files with 1495 additions and 947 deletions
37
lib/md033.js
37
lib/md033.js
|
@ -3,10 +3,10 @@
|
|||
"use strict";
|
||||
|
||||
const { addError } = require("../helpers");
|
||||
const { filterByTypes, parse } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypes, getHtmlTagInfo, parse } =
|
||||
require("../helpers/micromark.cjs");
|
||||
|
||||
// eslint-disable-next-line regexp/optimal-quantifier-concatenation
|
||||
const htmlTextRe = /^<([^!/\s>]+)[^\r\n>]*>?/;
|
||||
const nextLinesRe = /[\r\n][\s\S]*$/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD033", "no-inline-html" ],
|
||||
|
@ -20,20 +20,25 @@ module.exports = {
|
|||
let current = null;
|
||||
while ((current = pending.shift())) {
|
||||
const [ offset, tokens ] = current;
|
||||
for (const token of filterByTypes(tokens, "htmlFlow", "htmlText")) {
|
||||
for (const token of filterByTypes(tokens, [ "htmlFlow", "htmlText" ])) {
|
||||
if (token.type === "htmlText") {
|
||||
const match = htmlTextRe.exec(token.text);
|
||||
if (match) {
|
||||
const [ tag, element ] = match;
|
||||
if (!allowedElements.includes(element.toLowerCase())) {
|
||||
addError(
|
||||
onError,
|
||||
token.startLine + offset,
|
||||
"Element: " + element,
|
||||
undefined,
|
||||
[ token.startColumn, tag.length ]
|
||||
);
|
||||
}
|
||||
const htmlTagInfo = getHtmlTagInfo(token);
|
||||
if (
|
||||
htmlTagInfo &&
|
||||
!htmlTagInfo.close &&
|
||||
!allowedElements.includes(htmlTagInfo.name.toLowerCase())
|
||||
) {
|
||||
const range = [
|
||||
token.startColumn,
|
||||
token.text.replace(nextLinesRe, "").length
|
||||
];
|
||||
addError(
|
||||
onError,
|
||||
token.startLine + offset,
|
||||
"Element: " + htmlTagInfo.name,
|
||||
undefined,
|
||||
range
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// token.type === "htmlFlow"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue