refactor inline/block element determination
This commit is contained in:
parent
2a44eb3087
commit
18e61dc365
@ -35,19 +35,11 @@ block.list = (function() {
|
|||||||
block.html = (function() {
|
block.html = (function() {
|
||||||
var html = block.html.source;
|
var html = block.html.source;
|
||||||
|
|
||||||
// The real markdown checks for block elements.
|
|
||||||
// It's better to check for non-inline elements.
|
|
||||||
// Unknown elements will then be treated as block elements.
|
|
||||||
var closed = '<(?!(?:'
|
|
||||||
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
|
|
||||||
+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
|
|
||||||
+ '|span|br|wbr|ins|del|img)\\b)'
|
|
||||||
+ '(\\w+)[^\\0]+?</\\1>';
|
|
||||||
|
|
||||||
html = html
|
html = html
|
||||||
.replace('comment', /<!--[^\0]*?-->/.source)
|
.replace('comment', /<!--[^\0]*?-->/.source)
|
||||||
.replace('closed', closed)
|
.replace('closed', /<(?!elements)(\w+)[^\0]+?<\/\1>/.source)
|
||||||
.replace('closing', /<\w+(?!:\/|@)\b(?:"[^"]*"|'[^']*'|[^>])*>/.source);
|
.replace('closing', /<\w+(?!:\/|@)\b(?:"[^"]*"|'[^']*'|[^>])*>/.source)
|
||||||
|
.replace('elements', elements());
|
||||||
|
|
||||||
return new RegExp(html);
|
return new RegExp(html);
|
||||||
})();
|
})();
|
||||||
@ -57,7 +49,7 @@ block.paragraph = (function() {
|
|||||||
, body = [];
|
, body = [];
|
||||||
|
|
||||||
(function push(rule) {
|
(function push(rule) {
|
||||||
rule = rule.source || block[rule].source;
|
rule = block[rule] ? block[rule].source : rule;
|
||||||
body.push(rule.replace(/(^|[^\[])\^/g, '$1'));
|
body.push(rule.replace(/(^|[^\[])\^/g, '$1'));
|
||||||
return push;
|
return push;
|
||||||
})
|
})
|
||||||
@ -66,12 +58,7 @@ block.paragraph = (function() {
|
|||||||
('heading')
|
('heading')
|
||||||
('lheading')
|
('lheading')
|
||||||
('blockquote')
|
('blockquote')
|
||||||
(new RegExp('<'
|
('<(?!' + elements() + ')\\w+');
|
||||||
+ '(?:article|aside|audio|blockquote|canvas|caption|col|colgroup|dialog|div'
|
|
||||||
+ '|d[ltd]|embed|fieldset|figure|figcaption|footer|form|h[1-6r]|header'
|
|
||||||
+ '|hgroup|input|label|legend|li|nav|noscript|object|[ou]l|optgroup|option'
|
|
||||||
+ '|p|param|pre|script|section|select|source|table|t(?:body|foot|head)'
|
|
||||||
+ '|t[dhr]|textarea|video)\\b'));
|
|
||||||
|
|
||||||
return new
|
return new
|
||||||
RegExp(paragraph.replace('body', body.join('|')));
|
RegExp(paragraph.replace('body', body.join('|')));
|
||||||
@ -673,6 +660,15 @@ var mangle = function(str) {
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function elements() {
|
||||||
|
var elements = '(?:'
|
||||||
|
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
|
||||||
|
+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
|
||||||
|
+ '|span|br|wbr|ins|del|img)\\b';
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user