Skip to content

Commit

Permalink
Fixed inline html comments parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Jan 3, 2015
1 parent b7914cb commit 792f386
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/common/html_re.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ var open_tag = replace(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)
();

var close_tag = /<\/[A-Za-z][A-Za-z0-9]*\s*>/;
var comment = /<!--([^-]+|[-][^-]+)*-->/;
// That's less strict than http://www.w3.org/TR/html5/syntax.html#comments
// but we do the rest of check in "inline" rule.
var comment = /<!--[\s\S]*?-->/;
var processing = /<[?].*?[?]>/;
var declaration = /<![A-Z]+\s+[^>]*>/;
var cdata = /<!\[CDATA\[([^\]]+|\][^\]]|\]\][^>])*\]\]>/;
Expand Down
12 changes: 10 additions & 2 deletions lib/rules_inline/htmltag.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

var HTML_TAG_RE = require('../common/html_re').HTML_TAG_RE;

var COMMENT_RE = /^<!--[\s\S]*?-->$/;

function isLetter(ch) {
/*eslint no-bitwise:0*/
Expand All @@ -14,7 +15,7 @@ function isLetter(ch) {


module.exports = function htmltag(state, silent) {
var ch, match, max, pos = state.pos;
var ch, match, max, content, pos = state.pos;

if (!state.md.options.html) { return false; }

Expand All @@ -37,10 +38,17 @@ module.exports = function htmltag(state, silent) {
match = state.src.slice(pos).match(HTML_TAG_RE);
if (!match) { return false; }

content = state.src.slice(pos, pos + match[0].length);

// Additional check for comments
if (COMMENT_RE.test(content)) {
if (/(^>|^->|--|-$)/.test(content.slice(4, -3))) { return false; }
}

if (!silent) {
state.push({
type: 'htmltag',
content: state.src.slice(pos, pos + match[0].length),
content: content,
level: state.level
});
}
Expand Down

0 comments on commit 792f386

Please sign in to comment.