diff --git a/lib/common/html_re.js b/lib/common/html_re.js
index 44c7d2a..bb9d3b1 100644
--- a/lib/common/html_re.js
+++ b/lib/common/html_re.js
@@ -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 = //;
var processing = /<[?].*?[?]>/;
var declaration = /]*>/;
var cdata = /])*\]\]>/;
diff --git a/lib/rules_inline/htmltag.js b/lib/rules_inline/htmltag.js
index c0db00a..004eedd 100644
--- a/lib/rules_inline/htmltag.js
+++ b/lib/rules_inline/htmltag.js
@@ -5,6 +5,7 @@
var HTML_TAG_RE = require('../common/html_re').HTML_TAG_RE;
+var COMMENT_RE = /^$/;
function isLetter(ch) {
/*eslint no-bitwise:0*/
@@ -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; }
@@ -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
});
}