mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Update MD033/no-inline-html to better handle inline code spans (fixes #182).
This commit is contained in:
parent
f003926a72
commit
608f875fc2
4 changed files with 46 additions and 10 deletions
|
|
@ -6,8 +6,9 @@ const { addError, bareUrlRe, forEachLine, unescapeMarkdown } =
|
||||||
require("../helpers");
|
require("../helpers");
|
||||||
const { lineMetadata } = require("./cache");
|
const { lineMetadata } = require("./cache");
|
||||||
|
|
||||||
const htmlElementRe = /<(([\w+.-]+)(?:[^>]*)?)>/g;
|
const htmlElementRe = /<(([\w-]+)(?:[\s/][^>]*)?)>/g;
|
||||||
const linkDestinationRe = /]\(\s*$/;
|
const linkDestinationRe = /]\(\s*$/;
|
||||||
|
const inlineCodeRe = /^[^`]*(`+[^`]+`+[^`]+)*`+[^`]*$/;
|
||||||
// See https://spec.commonmark.org/0.29/#autolinks
|
// See https://spec.commonmark.org/0.29/#autolinks
|
||||||
const emailAddressRe =
|
const emailAddressRe =
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
|
|
@ -29,7 +30,7 @@ module.exports = {
|
||||||
!tag.endsWith("\\>") && !bareUrlRe.test(content) &&
|
!tag.endsWith("\\>") && !bareUrlRe.test(content) &&
|
||||||
!emailAddressRe.test(content)) {
|
!emailAddressRe.test(content)) {
|
||||||
const prefix = line.substring(0, match.index);
|
const prefix = line.substring(0, match.index);
|
||||||
if (!linkDestinationRe.test(prefix) &&
|
if (!linkDestinationRe.test(prefix) && !inlineCodeRe.test(prefix) &&
|
||||||
!unescapeMarkdown(prefix + "<", "_").endsWith("_")) {
|
!unescapeMarkdown(prefix + "<", "_").endsWith("_")) {
|
||||||
addError(onError, lineIndex + 1, "Element: " + element,
|
addError(onError, lineIndex + 1, "Element: " + element,
|
||||||
null, [ match.index + 1, tag.length ]);
|
null, [ match.index + 1, tag.length ]);
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,18 @@ text <strong>inline inline</strong> text
|
||||||
|
|
||||||
Text
|
Text
|
||||||
|
|
||||||
|
`<em>`
|
||||||
|
|
||||||
|
Text ``<em>`` text
|
||||||
|
|
||||||
|
Text `<em>` text ``<em>`` text ```<em>``` text
|
||||||
|
|
||||||
|
Text `<em>` text <em>inline</em> text
|
||||||
|
|
||||||
|
Text ``text <em> text`` text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
Text <a href="#anchor">inline</a> text
|
Text <a href="#anchor">inline</a> text
|
||||||
text <img src="src.png"/> text
|
text <img src="src.png"/> text
|
||||||
|
|
||||||
|
|
@ -82,10 +94,12 @@ Text
|
||||||
|
|
||||||
<name@example.com> is an email autolink.
|
<name@example.com> is an email autolink.
|
||||||
|
|
||||||
Text
|
|
||||||
|
|
||||||
Another email autolink: <first+last@ex.exa-mple.com>.
|
Another email autolink: <first+last@ex.exa-mple.com>.
|
||||||
|
|
||||||
Text
|
Text
|
||||||
|
|
||||||
But <foo.bar.baz> is not an email autolink.
|
<foo-bar-baz> is an HTML element.
|
||||||
|
|
||||||
|
But <foo.bar.baz> is not an autolink or HTML element.
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,16 @@
|
||||||
"errorRange": [ 8, 4 ]
|
"errorRange": [ 8, 4 ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lineNumber": 78,
|
"lineNumber": 84,
|
||||||
|
"ruleNames": [ "MD033", "no-inline-html" ],
|
||||||
|
"ruleDescription": "Inline HTML",
|
||||||
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033",
|
||||||
|
"errorDetail": "Element: em",
|
||||||
|
"errorContext": null,
|
||||||
|
"errorRange": [ 18, 4 ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lineNumber": 90,
|
||||||
"ruleNames": [ "MD033", "no-inline-html" ],
|
"ruleNames": [ "MD033", "no-inline-html" ],
|
||||||
"ruleDescription": "Inline HTML",
|
"ruleDescription": "Inline HTML",
|
||||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033",
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033",
|
||||||
|
|
@ -144,7 +153,7 @@
|
||||||
"errorRange": [ 6, 18 ]
|
"errorRange": [ 6, 18 ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lineNumber": 79,
|
"lineNumber": 91,
|
||||||
"ruleNames": [ "MD033", "no-inline-html" ],
|
"ruleNames": [ "MD033", "no-inline-html" ],
|
||||||
"ruleDescription": "Inline HTML",
|
"ruleDescription": "Inline HTML",
|
||||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033",
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033",
|
||||||
|
|
@ -153,12 +162,12 @@
|
||||||
"errorRange": [ 6, 20 ]
|
"errorRange": [ 6, 20 ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lineNumber": 91,
|
"lineNumber": 101,
|
||||||
"ruleNames": [ "MD033", "no-inline-html" ],
|
"ruleNames": [ "MD033", "no-inline-html" ],
|
||||||
"ruleDescription": "Inline HTML",
|
"ruleDescription": "Inline HTML",
|
||||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033",
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033",
|
||||||
"errorDetail": "Element: foo.bar.baz",
|
"errorDetail": "Element: foo-bar-baz",
|
||||||
"errorContext": null,
|
"errorContext": null,
|
||||||
"errorRange": [ 5, 13 ]
|
"errorRange": [ 1, 13 ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,20 @@
|
||||||
|
|
||||||
<br> {MD033}
|
<br> {MD033}
|
||||||
|
|
||||||
|
<br > {MD033}
|
||||||
|
|
||||||
<br/> {MD033}
|
<br/> {MD033}
|
||||||
|
|
||||||
|
<br /> {MD033}
|
||||||
|
|
||||||
|
<br attribute/> {MD033}
|
||||||
|
|
||||||
|
<br attribute /> {MD033}
|
||||||
|
|
||||||
|
<br attribute="value"/> {MD033}
|
||||||
|
|
||||||
|
<br attribute="value" /> {MD033}
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
This is allowed.
|
This is allowed.
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue