Browse Source

Fixed inline html comments parse

pull/25/head
Vitaly Puzrin 10 years ago
parent
commit
792f386840
  1. 4
      lib/common/html_re.js
  2. 12
      lib/rules_inline/htmltag.js

4
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 = /<!--[\s\S]*?-->/;
var processing = /<[?].*?[?]>/;
var declaration = /<![A-Z]+\s+[^>]*>/;
var cdata = /<!\[CDATA\[([^\]]+|\][^\]]|\]\][^>])*\]\]>/;

12
lib/rules_inline/htmltag.js

@ -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*/
@ -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
});
}

Loading…
Cancel
Save