mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Fix issue with MD044/proper-names where stateful RegExp could fail to match bare URLs, remove unnecessary use of bareUrlRe by MD033/no-inline-html.
This commit is contained in:
parent
57c661700a
commit
31ffe52f0f
4 changed files with 51 additions and 5 deletions
|
@ -2,8 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addError, bareUrlRe, forEachLine, unescapeMarkdown } =
|
||||
require("../helpers");
|
||||
const { addError, forEachLine, unescapeMarkdown } = require("../helpers");
|
||||
const { lineMetadata } = require("./cache");
|
||||
|
||||
const htmlElementRe = /<(([A-Za-z][A-Za-z0-9-]*)(?:\s[^>]*)?)\/?>/g;
|
||||
|
@ -24,10 +23,10 @@ module.exports = {
|
|||
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
||||
let match = null;
|
||||
// eslint-disable-next-line no-unmodified-loop-condition
|
||||
while (!inCode && (match = htmlElementRe.exec(line))) {
|
||||
while (!inCode && ((match = htmlElementRe.exec(line)) !== null)) {
|
||||
const [ tag, content, element ] = match;
|
||||
if (!allowedElements.includes(element.toLowerCase()) &&
|
||||
!tag.endsWith("\\>") && !bareUrlRe.test(content) &&
|
||||
!tag.endsWith("\\>") &&
|
||||
!emailAddressRe.test(content)) {
|
||||
const prefix = line.substring(0, match.index);
|
||||
if (!linkDestinationRe.test(prefix) && !inlineCodeRe.test(prefix)) {
|
||||
|
|
|
@ -24,7 +24,7 @@ module.exports = {
|
|||
let match = null;
|
||||
while ((match = anyNameRe.exec(line)) !== null) {
|
||||
const fullMatch = match[0];
|
||||
if (!bareUrlRe.test(fullMatch)) {
|
||||
if (fullMatch.search(bareUrlRe) === -1) {
|
||||
const wordMatch = fullMatch
|
||||
.replace(/^\W*/, "").replace(/\W*$/, "");
|
||||
if (!names.includes(wordMatch)) {
|
||||
|
|
14
test/proper-names-urls.json
Normal file
14
test/proper-names-urls.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"default": true,
|
||||
"proper-names": {
|
||||
"names": [
|
||||
"HTTPS",
|
||||
"EXAMPLE",
|
||||
"COM",
|
||||
"DIRECTORY",
|
||||
"FILE"
|
||||
]
|
||||
},
|
||||
"no-bare-urls": false,
|
||||
"code-block-style": false
|
||||
}
|
33
test/proper-names-urls.md
Normal file
33
test/proper-names-urls.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
# Proper Names in URLs
|
||||
|
||||
Text https text {MD044}
|
||||
Text example text {MD044}
|
||||
Text com text {MD044}
|
||||
Text directory text {MD044}
|
||||
Text file text {MD044}
|
||||
Text HTTPS EXAMPLE COM DIRECTORY FILE text
|
||||
|
||||
> The following lines are deliberately duplicated
|
||||
|
||||
Text https://example.com/directory/file text
|
||||
|
||||
Text https://example.com/directory/file text
|
||||
|
||||
Text <https://example.com/directory/file> text
|
||||
|
||||
Text <https://example.com/directory/file> text
|
||||
|
||||
Text [https://example.com/directory/file](https://example.com/directory/file) text
|
||||
|
||||
Text [https://example.com/directory/file](https://example.com/directory/file) text
|
||||
|
||||
Text `https://example.com/directory/file` text
|
||||
Text `https://example.com/directory/file` text
|
||||
|
||||
```text
|
||||
Text https://example.com/directory/file text
|
||||
Text https://example.com/directory/file text
|
||||
```
|
||||
|
||||
Text https://example.com/directory/file text
|
||||
Text https://example.com/directory/file text
|
Loading…
Add table
Add a link
Reference in a new issue