mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
parent
410da18a2c
commit
fb31bb5f35
4 changed files with 71 additions and 3 deletions
|
@ -709,6 +709,8 @@ items with hanging indents are okay:
|
||||||
|
|
||||||
Tags: html
|
Tags: html
|
||||||
|
|
||||||
|
Parameters: allowed_elements (array of string; default empty)
|
||||||
|
|
||||||
This rule is triggered whenever raw HTML is used in a markdown document:
|
This rule is triggered whenever raw HTML is used in a markdown document:
|
||||||
|
|
||||||
<h1>Inline HTML header</h1>
|
<h1>Inline HTML header</h1>
|
||||||
|
@ -721,6 +723,8 @@ Rationale: Raw HTML is allowed in markdown, but this rule is included for
|
||||||
those who want their documents to only include "pure" markdown, or for those
|
those who want their documents to only include "pure" markdown, or for those
|
||||||
who are rendering markdown documents in something other than HTML.
|
who are rendering markdown documents in something other than HTML.
|
||||||
|
|
||||||
|
Note: To allow specific HTML elements, use the 'allowed_elements' parameter.
|
||||||
|
|
||||||
## MD034 - Bare URL used
|
## MD034 - Bare URL used
|
||||||
|
|
||||||
Tags: links, url
|
Tags: links, url
|
||||||
|
|
23
lib/rules.js
23
lib/rules.js
|
@ -640,10 +640,27 @@ module.exports = [
|
||||||
"desc": "Inline HTML",
|
"desc": "Inline HTML",
|
||||||
"tags": [ "html" ],
|
"tags": [ "html" ],
|
||||||
"func": function MD033(params, errors) {
|
"func": function MD033(params, errors) {
|
||||||
|
var allowedElements = (params.options.allowed_elements || [])
|
||||||
|
.map(function forElement(element) {
|
||||||
|
return element.toLowerCase();
|
||||||
|
});
|
||||||
function forToken(token) {
|
function forToken(token) {
|
||||||
if (token.content.search(shared.inlineCommentRe) === -1) {
|
token.content.split(shared.newLineRe)
|
||||||
errors.push(token.lineNumber);
|
.forEach(function forLine(line, offset) {
|
||||||
}
|
var allowed = (line.match(/<[^/\s>!]*/g) || [])
|
||||||
|
.filter(function forElement(element) {
|
||||||
|
return element.length > 1;
|
||||||
|
})
|
||||||
|
.map(function forElement(element) {
|
||||||
|
return element.slice(1).toLowerCase();
|
||||||
|
})
|
||||||
|
.every(function forElement(element) {
|
||||||
|
return allowedElements.indexOf(element) !== -1;
|
||||||
|
});
|
||||||
|
if (!allowed) {
|
||||||
|
errors.push(token.lineNumber + offset);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
filterTokens(params, "html_block", forToken);
|
filterTokens(params, "html_block", forToken);
|
||||||
forEachInlineChild(params, "html_inline", forToken);
|
forEachInlineChild(params, "html_inline", forToken);
|
||||||
|
|
6
test/inline_html-allowed_elements.json
Normal file
6
test/inline_html-allowed_elements.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD033": {
|
||||||
|
"allowed_elements": [ "h1", "h3", "HR", "p" ]
|
||||||
|
}
|
||||||
|
}
|
41
test/inline_html-allowed_elements.md
Normal file
41
test/inline_html-allowed_elements.md
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<h1>This is allowed.</h1>
|
||||||
|
|
||||||
|
<h2>This is not allowed. {MD033}</h2>
|
||||||
|
|
||||||
|
<h3>This is allowed.</h3>
|
||||||
|
|
||||||
|
<h1>This <h2>is not</h2> allowed. {MD033}</h1>
|
||||||
|
|
||||||
|
<h3>This <h2>is not</h2> allowed. {MD033}</h3>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
|
||||||
|
<br> {MD033}
|
||||||
|
|
||||||
|
<br/> {MD033}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This is allowed.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<article> {MD033}
|
||||||
|
This is not allowed.
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<article> {MD033}
|
||||||
|
This is not allowed.
|
||||||
|
</article>
|
||||||
|
<hr/>
|
||||||
|
<br/> {MD033}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<P>
|
||||||
|
<Article> {MD033}
|
||||||
|
This is not allowed.
|
||||||
|
</Article>
|
||||||
|
<Hr/>
|
||||||
|
<Br/> {MD033}
|
||||||
|
</P>
|
Loading…
Add table
Add a link
Reference in a new issue