/*! domx-stringify - v1.0.0 - 2014-11-26
* http://esha.github.io/domx-stringify/
* Copyright (c) 2014 ESHA Research; Licensed MIT, GPL */
(function(D) {
"use strict";
// shortcuts
var X = D.x,
_ = X._;
var S = _.stringify = {
version: "1.0.0",
map: Array.prototype.map,
specialPrefix: '_',
markup: {
'\n': '
',
'<': '<',
'>': '>',
'': '</',
'\t': ' '
},
plain: {
'\n': '\n',
'<': '<',
'>': '>',
'': '',
'/>': '/>',
'\t': ' '
},
type: {
attr: 'attr',
string: 'string',
tag: 'tag',
},
print: function(el, markup, indent) {
var tag = el.tagName.toLowerCase(),
code = markup ? S.markup : S.plain,
line = S.isInline(el) ? '' : code['\n'],
content = S.content(el, markup, indent+code['\t'], line),
attrs = S.attrs(el, markup),
special = markup ? S.special(el) : [];
if (markup) {
tag = S.mark(tag, S.type.tag);
}
var open = S.mark(code['<'] + tag + (attrs ? ' '+attrs : '') + code['>'], special),
close = S.mark(code[''] + tag + code['>'], special);
if (content && line) {
content = line + content + line + indent;
}
return indent + open + content + close;
},
isInline: function(el) {
return (el.currentStyle || window.getComputedStyle(el,'')).display === 'inline' ||
el.tagName.match(/^(H\d|LI)$/i);
},
content: function(el, markup, indent, line) {
var s = [];
for (var i=0, m= el.childNodes.length; i'+value+'';
}
return value;
},
notEmpty: function(s) {
return s !== undefined && s !== null && s !== '';
}
};
X.add('stringify', function(markup, indent) {
return S.print(this, markup||false, indent||'');
});
})(document);