Browse Source

Use the same regexp for comments as reference parser

pull/41/head
Vitaly Puzrin 10 years ago
parent
commit
6ab7cc30a4
  1. 4
      lib/common/html_re.js
  2. 12
      lib/rules_inline/html_inline.js

4
lib/common/html_re.js

@ -41,9 +41,7 @@ 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 close_tag = /<\/[A-Za-z][A-Za-z0-9\-]*\s*>/;
// That's less strict than http://www.w3.org/TR/html5/syntax.html#comments var comment = /<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/;
// but we do the rest of check in "inline" rule.
var comment = /<!--[\s\S]*?-->/;
var processing = /<[?].*?[?]>/; var processing = /<[?].*?[?]>/;
var declaration = /<![A-Z]+\s+[^>]*>/; var declaration = /<![A-Z]+\s+[^>]*>/;
var cdata = /<!\[CDATA\[[\s\S]*?\]\]>/; var cdata = /<!\[CDATA\[[\s\S]*?\]\]>/;

12
lib/rules_inline/html_inline.js

@ -5,7 +5,6 @@
var HTML_TAG_RE = require('../common/html_re').HTML_TAG_RE; var HTML_TAG_RE = require('../common/html_re').HTML_TAG_RE;
var COMMENT_RE = /^<!--[\s\S]*?-->$/;
function isLetter(ch) { function isLetter(ch) {
/*eslint no-bitwise:0*/ /*eslint no-bitwise:0*/
@ -15,7 +14,7 @@ function isLetter(ch) {
module.exports = function html_inline(state, silent) { module.exports = function html_inline(state, silent) {
var ch, match, max, content, pos = state.pos; var ch, match, max, pos = state.pos;
if (!state.md.options.html) { return false; } if (!state.md.options.html) { return false; }
@ -38,17 +37,10 @@ module.exports = function html_inline(state, silent) {
match = state.src.slice(pos).match(HTML_TAG_RE); match = state.src.slice(pos).match(HTML_TAG_RE);
if (!match) { return false; } 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) { if (!silent) {
state.push({ state.push({
type: 'html_inline', type: 'html_inline',
content: content, content: state.src.slice(pos, pos + match[0].length),
level: state.level level: state.level
}); });
} }

Loading…
Cancel
Save