refactor inline/block element determination
This commit is contained in:
parent
2a44eb3087
commit
18e61dc365
@ -35,19 +35,11 @@ block.list = (function() {
|
||||
block.html = (function() {
|
||||
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
|
||||
.replace('comment', /<!--[^\0]*?-->/.source)
|
||||
.replace('closed', closed)
|
||||
.replace('closing', /<\w+(?!:\/|@)\b(?:"[^"]*"|'[^']*'|[^>])*>/.source);
|
||||
.replace('closed', /<(?!elements)(\w+)[^\0]+?<\/\1>/.source)
|
||||
.replace('closing', /<\w+(?!:\/|@)\b(?:"[^"]*"|'[^']*'|[^>])*>/.source)
|
||||
.replace('elements', elements());
|
||||
|
||||
return new RegExp(html);
|
||||
})();
|
||||
@ -57,7 +49,7 @@ block.paragraph = (function() {
|
||||
, body = [];
|
||||
|
||||
(function push(rule) {
|
||||
rule = rule.source || block[rule].source;
|
||||
rule = block[rule] ? block[rule].source : rule;
|
||||
body.push(rule.replace(/(^|[^\[])\^/g, '$1'));
|
||||
return push;
|
||||
})
|
||||
@ -66,12 +58,7 @@ block.paragraph = (function() {
|
||||
('heading')
|
||||
('lheading')
|
||||
('blockquote')
|
||||
(new RegExp('<'
|
||||
+ '(?: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'));
|
||||
('<(?!' + elements() + ')\\w+');
|
||||
|
||||
return new
|
||||
RegExp(paragraph.replace('body', body.join('|')));
|
||||
@ -673,6 +660,15 @@ var mangle = function(str) {
|
||||
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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user