forked from g21589/PPTX2HTML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tXml.min.js
4 lines (4 loc) · 1.37 KB
/
tXml.min.js
1
2
3
4
var _order=1;
function tXml(b){function c(){for(var g=[];b[a];){if(60==b.charCodeAt(a)){if(47===b.charCodeAt(a+1)){a=b.indexOf(">",a);break}else if(33===b.charCodeAt(a+1)){if(45==b.charCodeAt(a+2)){for(;62!==b.charCodeAt(a)||45!=b.charCodeAt(a-1)||45!=b.charCodeAt(a-2)||-1==a;)a=b.indexOf(">",a+1);-1===a&&(a=b.length)}else for(a+=2;62!==b.charCodeAt(a);a++);a++;continue}else if(63===b.charCodeAt(a+1)){a=b.indexOf(">",a);a++;continue}a++;for(var d=a;-1==="\r\n\t>/= ".indexOf(b[a]);a++);for(var f=b.slice(d,a),k=
!1,h={};62!==b.charCodeAt(a);a++)if(d=b.charCodeAt(a),64<d&&91>d||96<d&&123>d){for(d=a;-1==="\r\n\t>/= ".indexOf(b[a]);a++);for(var d=b.slice(d,a),e=b.charCodeAt(a);39!==e&&34!==e;)a++,e=b.charCodeAt(a);var e=b[a],l=++a;a=b.indexOf(e,l);e=b.slice(l,a);k||(h={},k=!0);h[d]=e}if(47!==b.charCodeAt(a-1)){a++;var m=c()}g.push({children:m,tagName:f,attrs:h})}else f=a,a=b.indexOf("<",a)-1,-2===a&&(a=b.length),f=b.slice(f,a+1),0<f.trim().length&&g.push(f);a++}return g}var a=0;_order=1;return simplefy(c())}
function simplefy(b){var c={};if(void 0===b)return{};if(1===b.length&&"string"==typeof b[0])return b[0];b.forEach(function(a){c[a.tagName]||(c[a.tagName]=[]);if("object"===typeof a){var b=simplefy(a.children);a.attrs&&(b.attrs=a.attrs);void 0===b.attrs?b.attrs={order:_order}:b.attrs.order=_order;_order++;c[a.tagName].push(b)}});for(var a in c)1==c[a].length&&(c[a]=c[a][0]);return c};