Allow exceptions for MD033 "Inline HTML" (fixes #3, fixes #4).

This commit is contained in:
David Anson 2015-12-15 21:30:37 -08:00
parent 410da18a2c
commit fb31bb5f35
4 changed files with 71 additions and 3 deletions

View file

@ -709,6 +709,8 @@ items with hanging indents are okay:
Tags: html
Parameters: allowed_elements (array of string; default empty)
This rule is triggered whenever raw HTML is used in a markdown document:
<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
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
Tags: links, url

View file

@ -640,10 +640,27 @@ module.exports = [
"desc": "Inline HTML",
"tags": [ "html" ],
"func": function MD033(params, errors) {
var allowedElements = (params.options.allowed_elements || [])
.map(function forElement(element) {
return element.toLowerCase();
});
function forToken(token) {
if (token.content.search(shared.inlineCommentRe) === -1) {
errors.push(token.lineNumber);
}
token.content.split(shared.newLineRe)
.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);
forEachInlineChild(params, "html_inline", forToken);

View file

@ -0,0 +1,6 @@
{
"default": true,
"MD033": {
"allowed_elements": [ "h1", "h3", "HR", "p" ]
}
}

View 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>