mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Upgrade to latest version of xmldom
This commit is contained in:
parent
d9fd722e50
commit
f4a015f120
0
plugins/tiddlywiki/xmldom/files/LICENSE
Normal file → Executable file
0
plugins/tiddlywiki/xmldom/files/LICENSE
Normal file → Executable file
74
plugins/tiddlywiki/xmldom/files/dom-parser.js
Normal file → Executable file
74
plugins/tiddlywiki/xmldom/files/dom-parser.js
Normal file → Executable file
@ -9,25 +9,24 @@ DOMParser.prototype.parseFromString = function(source,mimeType){
|
||||
var errorHandler = options.errorHandler;
|
||||
var locator = options.locator;
|
||||
var defaultNSMap = options.xmlns||{};
|
||||
var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
|
||||
var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
|
||||
var entityMap = isHTML?require('./entities').entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
|
||||
if(locator){
|
||||
domBuilder.setDocumentLocator(locator)
|
||||
}
|
||||
|
||||
sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
|
||||
sax.domBuilder = options.domBuilder || domBuilder;
|
||||
if(/\/x?html?$/.test(mimeType)){
|
||||
entityMap.nbsp = '\xa0';
|
||||
entityMap.copy = '\xa9';
|
||||
if(isHTML){
|
||||
defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
|
||||
}
|
||||
defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
|
||||
if(source){
|
||||
sax.parse(source,defaultNSMap,entityMap);
|
||||
}else{
|
||||
sax.errorHandler.error("invalid document source");
|
||||
sax.errorHandler.error("invalid doc source");
|
||||
}
|
||||
return domBuilder.document;
|
||||
return domBuilder.doc;
|
||||
}
|
||||
function buildErrorHandler(errorImpl,domBuilder,locator){
|
||||
if(!errorImpl){
|
||||
@ -41,27 +40,20 @@ function buildErrorHandler(errorImpl,domBuilder,locator){
|
||||
locator = locator||{}
|
||||
function build(key){
|
||||
var fn = errorImpl[key];
|
||||
if(!fn){
|
||||
if(isCallback){
|
||||
if(!fn && isCallback){
|
||||
fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
|
||||
}else{
|
||||
var i=arguments.length;
|
||||
while(--i){
|
||||
if(fn = errorImpl[arguments[i]]){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
errorHandler[key] = fn && function(msg){
|
||||
fn(msg+_locator(locator));
|
||||
fn('[xmldom '+key+']\t'+msg+_locator(locator));
|
||||
}||function(){};
|
||||
}
|
||||
build('warning','warn');
|
||||
build('error','warn','warning');
|
||||
build('fatalError','warn','warning','error');
|
||||
build('warning');
|
||||
build('error');
|
||||
build('fatalError');
|
||||
return errorHandler;
|
||||
}
|
||||
|
||||
//console.log('#\n\n\n\n\n\n\n####')
|
||||
/**
|
||||
* +ContentHandler+ErrorHandler
|
||||
* +LexicalHandler+EntityResolver2
|
||||
@ -84,13 +76,13 @@ function position(locator,node){
|
||||
*/
|
||||
DOMHandler.prototype = {
|
||||
startDocument : function() {
|
||||
this.document = new DOMImplementation().createDocument(null, null, null);
|
||||
this.doc = new DOMImplementation().createDocument(null, null, null);
|
||||
if (this.locator) {
|
||||
this.document.documentURI = this.locator.systemId;
|
||||
this.doc.documentURI = this.locator.systemId;
|
||||
}
|
||||
},
|
||||
startElement:function(namespaceURI, localName, qName, attrs) {
|
||||
var doc = this.document;
|
||||
var doc = this.doc;
|
||||
var el = doc.createElementNS(namespaceURI, qName||localName);
|
||||
var len = attrs.length;
|
||||
appendElement(this, el);
|
||||
@ -102,9 +94,7 @@ DOMHandler.prototype = {
|
||||
var value = attrs.getValue(i);
|
||||
var qName = attrs.getQName(i);
|
||||
var attr = doc.createAttributeNS(namespaceURI, qName);
|
||||
if( attr.getOffset){
|
||||
position(attr.getOffset(1),attr)
|
||||
}
|
||||
this.locator &&position(attrs.getLocator(i),attr);
|
||||
attr.value = attr.nodeValue = value;
|
||||
el.setAttributeNode(attr)
|
||||
}
|
||||
@ -119,7 +109,7 @@ DOMHandler.prototype = {
|
||||
endPrefixMapping:function(prefix) {
|
||||
},
|
||||
processingInstruction:function(target, data) {
|
||||
var ins = this.document.createProcessingInstruction(target, data);
|
||||
var ins = this.doc.createProcessingInstruction(target, data);
|
||||
this.locator && position(this.locator,ins)
|
||||
appendElement(this, ins);
|
||||
},
|
||||
@ -128,13 +118,17 @@ DOMHandler.prototype = {
|
||||
characters:function(chars, start, length) {
|
||||
chars = _toString.apply(this,arguments)
|
||||
//console.log(chars)
|
||||
if(this.currentElement && chars){
|
||||
if(chars){
|
||||
if (this.cdata) {
|
||||
var charNode = this.document.createCDATASection(chars);
|
||||
this.currentElement.appendChild(charNode);
|
||||
var charNode = this.doc.createCDATASection(chars);
|
||||
} else {
|
||||
var charNode = this.document.createTextNode(chars);
|
||||
var charNode = this.doc.createTextNode(chars);
|
||||
}
|
||||
if(this.currentElement){
|
||||
this.currentElement.appendChild(charNode);
|
||||
}else if(/^\s*$/.test(chars)){
|
||||
this.doc.appendChild(charNode);
|
||||
//process xml
|
||||
}
|
||||
this.locator && position(this.locator,charNode)
|
||||
}
|
||||
@ -142,7 +136,7 @@ DOMHandler.prototype = {
|
||||
skippedEntity:function(name) {
|
||||
},
|
||||
endDocument:function() {
|
||||
this.document.normalize();
|
||||
this.doc.normalize();
|
||||
},
|
||||
setDocumentLocator:function (locator) {
|
||||
if(this.locator = locator){// && !('lineNumber' in locator)){
|
||||
@ -152,7 +146,7 @@ DOMHandler.prototype = {
|
||||
//LexicalHandler
|
||||
comment:function(chars, start, length) {
|
||||
chars = _toString.apply(this,arguments)
|
||||
var comm = this.document.createComment(chars);
|
||||
var comm = this.doc.createComment(chars);
|
||||
this.locator && position(this.locator,comm)
|
||||
appendElement(this, comm);
|
||||
},
|
||||
@ -166,7 +160,7 @@ DOMHandler.prototype = {
|
||||
},
|
||||
|
||||
startDTD:function(name, publicId, systemId) {
|
||||
var impl = this.document.implementation;
|
||||
var impl = this.doc.implementation;
|
||||
if (impl && impl.createDocumentType) {
|
||||
var dt = impl.createDocumentType(name, publicId, systemId);
|
||||
this.locator && position(this.locator,dt)
|
||||
@ -178,13 +172,13 @@ DOMHandler.prototype = {
|
||||
* @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
|
||||
*/
|
||||
warning:function(error) {
|
||||
console.warn(error,_locator(this.locator));
|
||||
console.warn('[xmldom warning]\t'+error,_locator(this.locator));
|
||||
},
|
||||
error:function(error) {
|
||||
console.error(error,_locator(this.locator));
|
||||
console.error('[xmldom error]\t'+error,_locator(this.locator));
|
||||
},
|
||||
fatalError:function(error) {
|
||||
console.error(error,_locator(this.locator));
|
||||
console.error('[xmldom fatalError]\t'+error,_locator(this.locator));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@ -242,15 +236,15 @@ function _toString(chars,start,length){
|
||||
/* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
|
||||
function appendElement (hander,node) {
|
||||
if (!hander.currentElement) {
|
||||
hander.document.appendChild(node);
|
||||
hander.doc.appendChild(node);
|
||||
} else {
|
||||
hander.currentElement.appendChild(node);
|
||||
}
|
||||
}//appendChild and setAttributeNS are preformance key
|
||||
|
||||
if(typeof require == 'function'){
|
||||
//if(typeof require == 'function'){
|
||||
var XMLReader = require('./sax').XMLReader;
|
||||
var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
|
||||
exports.XMLSerializer = require('./dom').XMLSerializer ;
|
||||
exports.DOMParser = DOMParser;
|
||||
}
|
||||
//}
|
||||
|
165
plugins/tiddlywiki/xmldom/files/dom.js
Normal file → Executable file
165
plugins/tiddlywiki/xmldom/files/dom.js
Normal file → Executable file
@ -109,6 +109,12 @@ NodeList.prototype = {
|
||||
*/
|
||||
item: function(index) {
|
||||
return this[index] || null;
|
||||
},
|
||||
toString:function(isHTML,nodeFilter){
|
||||
for(var buf = [], i = 0;i<this.length;i++){
|
||||
serializeToString(this[i],buf,isHTML,nodeFilter);
|
||||
}
|
||||
return buf.join('');
|
||||
}
|
||||
};
|
||||
function LiveNodeList(node,refresh){
|
||||
@ -164,6 +170,7 @@ function _addNamedNode(el,list,newAttr,oldAttr){
|
||||
}
|
||||
}
|
||||
function _removeNamedNode(el,list,attr){
|
||||
//console.log('remove attr:'+attr)
|
||||
var i = _findNodeIndex(list,attr);
|
||||
if(i>=0){
|
||||
var lastIndex = list.length-1
|
||||
@ -179,7 +186,7 @@ function _removeNamedNode(el,list,attr){
|
||||
}
|
||||
}
|
||||
}else{
|
||||
throw DOMException(NOT_FOUND_ERR,new Error())
|
||||
throw DOMException(NOT_FOUND_ERR,new Error(el.tagName+'@'+attr))
|
||||
}
|
||||
}
|
||||
NamedNodeMap.prototype = {
|
||||
@ -189,9 +196,11 @@ NamedNodeMap.prototype = {
|
||||
// if(key.indexOf(':')>0 || key == 'xmlns'){
|
||||
// return null;
|
||||
// }
|
||||
//console.log()
|
||||
var i = this.length;
|
||||
while(i--){
|
||||
var attr = this[i];
|
||||
//console.log(attr.nodeName,key)
|
||||
if(attr.nodeName == key){
|
||||
return attr;
|
||||
}
|
||||
@ -373,7 +382,7 @@ Node.prototype = {
|
||||
}
|
||||
}
|
||||
}
|
||||
el = el.nodeType == 2?el.ownerDocument : el.parentNode;
|
||||
el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@ -388,7 +397,7 @@ Node.prototype = {
|
||||
return map[prefix] ;
|
||||
}
|
||||
}
|
||||
el = el.nodeType == 2?el.ownerDocument : el.parentNode;
|
||||
el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@ -573,7 +582,7 @@ Document.prototype = {
|
||||
}
|
||||
return newChild;
|
||||
}
|
||||
if(this.documentElement == null && newChild.nodeType == 1){
|
||||
if(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){
|
||||
this.documentElement = newChild;
|
||||
}
|
||||
|
||||
@ -593,7 +602,7 @@ Document.prototype = {
|
||||
getElementById : function(id){
|
||||
var rtv = null;
|
||||
_visitNode(this.documentElement,function(node){
|
||||
if(node.nodeType == 1){
|
||||
if(node.nodeType == ELEMENT_NODE){
|
||||
if(node.getAttribute('id') == id){
|
||||
rtv = node;
|
||||
return true;
|
||||
@ -742,6 +751,7 @@ Element.prototype = {
|
||||
return this.attributes.setNamedItemNS(newAttr);
|
||||
},
|
||||
removeAttributeNode : function(oldAttr){
|
||||
//console.log(this == oldAttr.ownerElement)
|
||||
return this.attributes.removeNamedItem(oldAttr.nodeName);
|
||||
},
|
||||
//get real attribute name,and remove it by removeAttributeNode
|
||||
@ -786,6 +796,7 @@ Element.prototype = {
|
||||
}
|
||||
});
|
||||
return ls;
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -817,10 +828,7 @@ CharacterData.prototype = {
|
||||
|
||||
},
|
||||
appendChild:function(newChild){
|
||||
//if(!(newChild instanceof CharacterData)){
|
||||
throw new Error(ExceptionMessage[3])
|
||||
//}
|
||||
return Node.prototype.appendChild.apply(this,arguments)
|
||||
throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR])
|
||||
},
|
||||
deleteData: function(offset, count) {
|
||||
this.replaceData(offset,count,"");
|
||||
@ -902,39 +910,132 @@ function ProcessingInstruction() {
|
||||
ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
|
||||
_extends(ProcessingInstruction,Node);
|
||||
function XMLSerializer(){}
|
||||
XMLSerializer.prototype.serializeToString = function(node,attributeSorter){
|
||||
return node.toString(attributeSorter);
|
||||
XMLSerializer.prototype.serializeToString = function(node,isHtml,nodeFilter){
|
||||
return nodeSerializeToString.call(node,isHtml,nodeFilter);
|
||||
}
|
||||
Node.prototype.toString =function(attributeSorter){
|
||||
Node.prototype.toString = nodeSerializeToString;
|
||||
function nodeSerializeToString(isHtml,nodeFilter){
|
||||
var buf = [];
|
||||
serializeToString(this,buf,attributeSorter);
|
||||
var refNode = this.nodeType == 9 && this.documentElement || this;
|
||||
var prefix = refNode.prefix;
|
||||
var uri = refNode.namespaceURI;
|
||||
|
||||
if(uri && prefix == null){
|
||||
//console.log(prefix)
|
||||
var prefix = refNode.lookupPrefix(uri);
|
||||
if(prefix == null){
|
||||
//isHTML = true;
|
||||
var visibleNamespaces=[
|
||||
{namespace:uri,prefix:null}
|
||||
//{namespace:uri,prefix:''}
|
||||
]
|
||||
}
|
||||
}
|
||||
serializeToString(this,buf,isHtml,nodeFilter,visibleNamespaces);
|
||||
//console.log('###',this.nodeType,uri,prefix,buf.join(''))
|
||||
return buf.join('');
|
||||
}
|
||||
function serializeToString(node,buf,attributeSorter,isHTML){
|
||||
function needNamespaceDefine(node,isHTML, visibleNamespaces) {
|
||||
var prefix = node.prefix||'';
|
||||
var uri = node.namespaceURI;
|
||||
if (!prefix && !uri){
|
||||
return false;
|
||||
}
|
||||
if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace"
|
||||
|| uri == 'http://www.w3.org/2000/xmlns/'){
|
||||
return false;
|
||||
}
|
||||
|
||||
var i = visibleNamespaces.length
|
||||
//console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces)
|
||||
while (i--) {
|
||||
var ns = visibleNamespaces[i];
|
||||
// get namespace prefix
|
||||
//console.log(node.nodeType,node.tagName,ns.prefix,prefix)
|
||||
if (ns.prefix == prefix){
|
||||
return ns.namespace != uri;
|
||||
}
|
||||
}
|
||||
//console.log(isHTML,uri,prefix=='')
|
||||
//if(isHTML && prefix ==null && uri == 'http://www.w3.org/1999/xhtml'){
|
||||
// return false;
|
||||
//}
|
||||
//node.flag = '11111'
|
||||
//console.error(3,true,node.flag,node.prefix,node.namespaceURI)
|
||||
return true;
|
||||
}
|
||||
function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
|
||||
if(nodeFilter){
|
||||
node = nodeFilter(node);
|
||||
if(node){
|
||||
if(typeof node == 'string'){
|
||||
buf.push(node);
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
//buf.sort.apply(attrs, attributeSorter);
|
||||
}
|
||||
switch(node.nodeType){
|
||||
case ELEMENT_NODE:
|
||||
if (!visibleNamespaces) visibleNamespaces = [];
|
||||
var startVisibleNamespaces = visibleNamespaces.length;
|
||||
var attrs = node.attributes;
|
||||
var len = attrs.length;
|
||||
var child = node.firstChild;
|
||||
var nodeName = node.tagName;
|
||||
|
||||
isHTML = (htmlns === node.namespaceURI) ||isHTML
|
||||
buf.push('<',nodeName);
|
||||
if(attributeSorter){
|
||||
buf.sort.apply(attrs, attributeSorter);
|
||||
|
||||
|
||||
|
||||
for(var i=0;i<len;i++){
|
||||
// add namespaces for attributes
|
||||
var attr = attrs.item(i);
|
||||
if (attr.prefix == 'xmlns') {
|
||||
visibleNamespaces.push({ prefix: attr.localName, namespace: attr.value });
|
||||
}else if(attr.nodeName == 'xmlns'){
|
||||
visibleNamespaces.push({ prefix: '', namespace: attr.value });
|
||||
}
|
||||
}
|
||||
for(var i=0;i<len;i++){
|
||||
serializeToString(attrs.item(i),buf,attributeSorter,isHTML);
|
||||
var attr = attrs.item(i);
|
||||
if (needNamespaceDefine(attr,isHTML, visibleNamespaces)) {
|
||||
var prefix = attr.prefix||'';
|
||||
var uri = attr.namespaceURI;
|
||||
var ns = prefix ? ' xmlns:' + prefix : " xmlns";
|
||||
buf.push(ns, '="' , uri , '"');
|
||||
visibleNamespaces.push({ prefix: prefix, namespace:uri });
|
||||
}
|
||||
if(child || isHTML && !/^(?:meta|link|img|br|hr|input|button)$/i.test(nodeName)){
|
||||
serializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces);
|
||||
}
|
||||
// add namespace for current node
|
||||
if (needNamespaceDefine(node,isHTML, visibleNamespaces)) {
|
||||
var prefix = node.prefix||'';
|
||||
var uri = node.namespaceURI;
|
||||
var ns = prefix ? ' xmlns:' + prefix : " xmlns";
|
||||
buf.push(ns, '="' , uri , '"');
|
||||
visibleNamespaces.push({ prefix: prefix, namespace:uri });
|
||||
}
|
||||
|
||||
if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){
|
||||
buf.push('>');
|
||||
//if is cdata child node
|
||||
if(isHTML && /^script$/i.test(nodeName)){
|
||||
if(child){
|
||||
buf.push(child.data);
|
||||
}
|
||||
}else{
|
||||
while(child){
|
||||
serializeToString(child,buf,attributeSorter,isHTML);
|
||||
if(child.data){
|
||||
buf.push(child.data);
|
||||
}else{
|
||||
serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
|
||||
}
|
||||
child = child.nextSibling;
|
||||
}
|
||||
}else
|
||||
{
|
||||
while(child){
|
||||
serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
|
||||
child = child.nextSibling;
|
||||
}
|
||||
}
|
||||
@ -942,12 +1043,14 @@ function serializeToString(node,buf,attributeSorter,isHTML){
|
||||
}else{
|
||||
buf.push('/>');
|
||||
}
|
||||
// remove added visible namespaces
|
||||
//visibleNamespaces.length = startVisibleNamespaces;
|
||||
return;
|
||||
case DOCUMENT_NODE:
|
||||
case DOCUMENT_FRAGMENT_NODE:
|
||||
var child = node.firstChild;
|
||||
while(child){
|
||||
serializeToString(child,buf,attributeSorter,isHTML);
|
||||
serializeToString(child,buf,isHTML,nodeFilter,visibleNamespaces);
|
||||
child = child.nextSibling;
|
||||
}
|
||||
return;
|
||||
@ -1092,8 +1195,8 @@ try{
|
||||
},
|
||||
set:function(data){
|
||||
switch(this.nodeType){
|
||||
case 1:
|
||||
case 11:
|
||||
case ELEMENT_NODE:
|
||||
case DOCUMENT_FRAGMENT_NODE:
|
||||
while(this.firstChild){
|
||||
this.removeChild(this.firstChild);
|
||||
}
|
||||
@ -1104,7 +1207,7 @@ try{
|
||||
default:
|
||||
//TODO:
|
||||
this.data = data;
|
||||
this.value = value;
|
||||
this.value = data;
|
||||
this.nodeValue = data;
|
||||
}
|
||||
}
|
||||
@ -1112,8 +1215,8 @@ try{
|
||||
|
||||
function getTextContent(node){
|
||||
switch(node.nodeType){
|
||||
case 1:
|
||||
case 11:
|
||||
case ELEMENT_NODE:
|
||||
case DOCUMENT_FRAGMENT_NODE:
|
||||
var buf = [];
|
||||
node = node.firstChild;
|
||||
while(node){
|
||||
@ -1135,7 +1238,7 @@ try{
|
||||
}catch(e){//ie8
|
||||
}
|
||||
|
||||
if(typeof require == 'function'){
|
||||
//if(typeof require == 'function'){
|
||||
exports.DOMImplementation = DOMImplementation;
|
||||
exports.XMLSerializer = XMLSerializer;
|
||||
}
|
||||
//}
|
||||
|
244
plugins/tiddlywiki/xmldom/files/entities.js
Executable file
244
plugins/tiddlywiki/xmldom/files/entities.js
Executable file
@ -0,0 +1,244 @@
|
||||
exports.entityMap = {
|
||||
lt: '<',
|
||||
gt: '>',
|
||||
amp: '&',
|
||||
quot: '"',
|
||||
apos: "'",
|
||||
Agrave: "À",
|
||||
Aacute: "Á",
|
||||
Acirc: "Â",
|
||||
Atilde: "Ã",
|
||||
Auml: "Ä",
|
||||
Aring: "Å",
|
||||
AElig: "Æ",
|
||||
Ccedil: "Ç",
|
||||
Egrave: "È",
|
||||
Eacute: "É",
|
||||
Ecirc: "Ê",
|
||||
Euml: "Ë",
|
||||
Igrave: "Ì",
|
||||
Iacute: "Í",
|
||||
Icirc: "Î",
|
||||
Iuml: "Ï",
|
||||
ETH: "Ð",
|
||||
Ntilde: "Ñ",
|
||||
Ograve: "Ò",
|
||||
Oacute: "Ó",
|
||||
Ocirc: "Ô",
|
||||
Otilde: "Õ",
|
||||
Ouml: "Ö",
|
||||
Oslash: "Ø",
|
||||
Ugrave: "Ù",
|
||||
Uacute: "Ú",
|
||||
Ucirc: "Û",
|
||||
Uuml: "Ü",
|
||||
Yacute: "Ý",
|
||||
THORN: "Þ",
|
||||
szlig: "ß",
|
||||
agrave: "à",
|
||||
aacute: "á",
|
||||
acirc: "â",
|
||||
atilde: "ã",
|
||||
auml: "ä",
|
||||
aring: "å",
|
||||
aelig: "æ",
|
||||
ccedil: "ç",
|
||||
egrave: "è",
|
||||
eacute: "é",
|
||||
ecirc: "ê",
|
||||
euml: "ë",
|
||||
igrave: "ì",
|
||||
iacute: "í",
|
||||
icirc: "î",
|
||||
iuml: "ï",
|
||||
eth: "ð",
|
||||
ntilde: "ñ",
|
||||
ograve: "ò",
|
||||
oacute: "ó",
|
||||
ocirc: "ô",
|
||||
otilde: "õ",
|
||||
ouml: "ö",
|
||||
oslash: "ø",
|
||||
ugrave: "ù",
|
||||
uacute: "ú",
|
||||
ucirc: "û",
|
||||
uuml: "ü",
|
||||
yacute: "ý",
|
||||
thorn: "þ",
|
||||
yuml: "ÿ",
|
||||
nbsp: " ",
|
||||
iexcl: "¡",
|
||||
cent: "¢",
|
||||
pound: "£",
|
||||
curren: "¤",
|
||||
yen: "¥",
|
||||
brvbar: "¦",
|
||||
sect: "§",
|
||||
uml: "¨",
|
||||
copy: "©",
|
||||
ordf: "ª",
|
||||
laquo: "«",
|
||||
not: "¬",
|
||||
shy: "",
|
||||
reg: "®",
|
||||
macr: "¯",
|
||||
deg: "°",
|
||||
plusmn: "±",
|
||||
sup2: "²",
|
||||
sup3: "³",
|
||||
acute: "´",
|
||||
micro: "µ",
|
||||
para: "¶",
|
||||
middot: "·",
|
||||
cedil: "¸",
|
||||
sup1: "¹",
|
||||
ordm: "º",
|
||||
raquo: "»",
|
||||
frac14: "¼",
|
||||
frac12: "½",
|
||||
frac34: "¾",
|
||||
iquest: "¿",
|
||||
times: "×",
|
||||
divide: "÷",
|
||||
forall: "∀",
|
||||
part: "∂",
|
||||
exist: "∃",
|
||||
empty: "∅",
|
||||
nabla: "∇",
|
||||
isin: "∈",
|
||||
notin: "∉",
|
||||
ni: "∋",
|
||||
prod: "∏",
|
||||
sum: "∑",
|
||||
minus: "−",
|
||||
lowast: "∗",
|
||||
radic: "√",
|
||||
prop: "∝",
|
||||
infin: "∞",
|
||||
ang: "∠",
|
||||
and: "∧",
|
||||
or: "∨",
|
||||
cap: "∩",
|
||||
cup: "∪",
|
||||
'int': "∫",
|
||||
there4: "∴",
|
||||
sim: "∼",
|
||||
cong: "≅",
|
||||
asymp: "≈",
|
||||
ne: "≠",
|
||||
equiv: "≡",
|
||||
le: "≤",
|
||||
ge: "≥",
|
||||
sub: "⊂",
|
||||
sup: "⊃",
|
||||
nsub: "⊄",
|
||||
sube: "⊆",
|
||||
supe: "⊇",
|
||||
oplus: "⊕",
|
||||
otimes: "⊗",
|
||||
perp: "⊥",
|
||||
sdot: "⋅",
|
||||
Alpha: "Α",
|
||||
Beta: "Β",
|
||||
Gamma: "Γ",
|
||||
Delta: "Δ",
|
||||
Epsilon: "Ε",
|
||||
Zeta: "Ζ",
|
||||
Eta: "Η",
|
||||
Theta: "Θ",
|
||||
Iota: "Ι",
|
||||
Kappa: "Κ",
|
||||
Lambda: "Λ",
|
||||
Mu: "Μ",
|
||||
Nu: "Ν",
|
||||
Xi: "Ξ",
|
||||
Omicron: "Ο",
|
||||
Pi: "Π",
|
||||
Rho: "Ρ",
|
||||
Sigma: "Σ",
|
||||
Tau: "Τ",
|
||||
Upsilon: "Υ",
|
||||
Phi: "Φ",
|
||||
Chi: "Χ",
|
||||
Psi: "Ψ",
|
||||
Omega: "Ω",
|
||||
alpha: "α",
|
||||
beta: "β",
|
||||
gamma: "γ",
|
||||
delta: "δ",
|
||||
epsilon: "ε",
|
||||
zeta: "ζ",
|
||||
eta: "η",
|
||||
theta: "θ",
|
||||
iota: "ι",
|
||||
kappa: "κ",
|
||||
lambda: "λ",
|
||||
mu: "μ",
|
||||
nu: "ν",
|
||||
xi: "ξ",
|
||||
omicron: "ο",
|
||||
pi: "π",
|
||||
rho: "ρ",
|
||||
sigmaf: "ς",
|
||||
sigma: "σ",
|
||||
tau: "τ",
|
||||
upsilon: "υ",
|
||||
phi: "φ",
|
||||
chi: "χ",
|
||||
psi: "ψ",
|
||||
omega: "ω",
|
||||
thetasym: "ϑ",
|
||||
upsih: "ϒ",
|
||||
piv: "ϖ",
|
||||
OElig: "Œ",
|
||||
oelig: "œ",
|
||||
Scaron: "Š",
|
||||
scaron: "š",
|
||||
Yuml: "Ÿ",
|
||||
fnof: "ƒ",
|
||||
circ: "ˆ",
|
||||
tilde: "˜",
|
||||
ensp: " ",
|
||||
emsp: " ",
|
||||
thinsp: " ",
|
||||
zwnj: "",
|
||||
zwj: "",
|
||||
lrm: "",
|
||||
rlm: "",
|
||||
ndash: "–",
|
||||
mdash: "—",
|
||||
lsquo: "‘",
|
||||
rsquo: "’",
|
||||
sbquo: "‚",
|
||||
ldquo: "“",
|
||||
rdquo: "”",
|
||||
bdquo: "„",
|
||||
dagger: "†",
|
||||
Dagger: "‡",
|
||||
bull: "•",
|
||||
hellip: "…",
|
||||
permil: "‰",
|
||||
prime: "′",
|
||||
Prime: "″",
|
||||
lsaquo: "‹",
|
||||
rsaquo: "›",
|
||||
oline: "‾",
|
||||
euro: "€",
|
||||
trade: "™",
|
||||
larr: "←",
|
||||
uarr: "↑",
|
||||
rarr: "→",
|
||||
darr: "↓",
|
||||
harr: "↔",
|
||||
crarr: "↵",
|
||||
lceil: "⌈",
|
||||
rceil: "⌉",
|
||||
lfloor: "⌊",
|
||||
rfloor: "⌋",
|
||||
loz: "◊",
|
||||
spades: "♠",
|
||||
clubs: "♣",
|
||||
hearts: "♥",
|
||||
diams: "♦"
|
||||
};
|
||||
//for(var n in exports.entityMap){console.log(exports.entityMap[n].charCodeAt())}
|
0
plugins/tiddlywiki/xmldom/files/readme.md
Normal file → Executable file
0
plugins/tiddlywiki/xmldom/files/readme.md
Normal file → Executable file
199
plugins/tiddlywiki/xmldom/files/sax.js
Normal file → Executable file
199
plugins/tiddlywiki/xmldom/files/sax.js
Normal file → Executable file
@ -2,21 +2,21 @@
|
||||
//[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
|
||||
//[5] Name ::= NameStartChar (NameChar)*
|
||||
var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]///\u10000-\uEFFFF
|
||||
var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\u00B7\u0300-\u036F\\u203F-\u2040]");
|
||||
var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
|
||||
var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
|
||||
//var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
|
||||
//var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')
|
||||
|
||||
//S_TAG, S_ATTR, S_EQ, S_V
|
||||
//S_ATTR_S, S_E, S_S, S_C
|
||||
//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
|
||||
//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
|
||||
var S_TAG = 0;//tag name offerring
|
||||
var S_ATTR = 1;//attr name offerring
|
||||
var S_ATTR_S=2;//attr name end and space offer
|
||||
var S_ATTR_SPACE=2;//attr name end and space offer
|
||||
var S_EQ = 3;//=space?
|
||||
var S_V = 4;//attr value(no quot value only)
|
||||
var S_E = 5;//attr value end and no space(quot end)
|
||||
var S_S = 6;//(attr value end || tag end ) && (space offer)
|
||||
var S_C = 7;//closed el<el />
|
||||
var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
|
||||
var S_ATTR_END = 5;//attr value end and no space(quot end)
|
||||
var S_TAG_SPACE = 6;//(attr value end || tag end ) && (space offer)
|
||||
var S_TAG_CLOSE = 7;//closed el<el />
|
||||
|
||||
function XMLReader(){
|
||||
|
||||
@ -76,7 +76,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
}
|
||||
var lineStart = 0;
|
||||
var lineEnd = 0;
|
||||
var linePattern = /.+(?:\r\n?|\n)|.*$/g
|
||||
var linePattern = /.*(?:\r\n?|\n)|.*$/g
|
||||
var locator = domBuilder.locator;
|
||||
|
||||
var parseStack = [{currentNSMap:defaultNSMapCopy}]
|
||||
@ -87,7 +87,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
var tagStart = source.indexOf('<',start);
|
||||
if(tagStart<0){
|
||||
if(!source.substr(start).match(/^\s*$/)){
|
||||
var doc = domBuilder.document;
|
||||
var doc = domBuilder.doc;
|
||||
var text = doc.createTextNode(source.substr(start));
|
||||
doc.appendChild(text);
|
||||
domBuilder.currentElement = text;
|
||||
@ -102,16 +102,36 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
var end = source.indexOf('>',tagStart+3);
|
||||
var tagName = source.substring(tagStart+2,end);
|
||||
var config = parseStack.pop();
|
||||
var localNSMap = config.localNSMap;
|
||||
if(config.tagName != tagName){
|
||||
errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName );
|
||||
if(end<0){
|
||||
|
||||
tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
|
||||
//console.error('#@@@@@@'+tagName)
|
||||
errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
|
||||
end = tagStart+1+tagName.length;
|
||||
}else if(tagName.match(/\s</)){
|
||||
tagName = tagName.replace(/[\s<].*/,'');
|
||||
errorHandler.error("end tag name: "+tagName+' maybe not complete');
|
||||
end = tagStart+1+tagName.length;
|
||||
}
|
||||
//console.error(parseStack.length,parseStack)
|
||||
//console.error(config);
|
||||
var localNSMap = config.localNSMap;
|
||||
var endMatch = config.tagName == tagName;
|
||||
var endIgnoreCaseMach = endMatch || config.tagName&&config.tagName.toLowerCase() == tagName.toLowerCase()
|
||||
if(endIgnoreCaseMach){
|
||||
domBuilder.endElement(config.uri,config.localName,tagName);
|
||||
if(localNSMap){
|
||||
for(var prefix in localNSMap){
|
||||
domBuilder.endPrefixMapping(prefix) ;
|
||||
}
|
||||
}
|
||||
if(!endMatch){
|
||||
errorHandler.fatalError("end tag name: "+tagName+' is not match the current start tagName:'+config.tagName );
|
||||
}
|
||||
}else{
|
||||
parseStack.push(config)
|
||||
}
|
||||
|
||||
end++;
|
||||
break;
|
||||
// end elment
|
||||
@ -124,33 +144,40 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
end = parseDCC(source,tagStart,domBuilder,errorHandler);
|
||||
break;
|
||||
default:
|
||||
|
||||
locator&&position(tagStart);
|
||||
|
||||
var el = new ElementAttributes();
|
||||
|
||||
var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
|
||||
//elStartEnd
|
||||
var end = parseElementStartPart(source,tagStart,el,entityReplacer,errorHandler);
|
||||
var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
|
||||
var len = el.length;
|
||||
|
||||
if(locator){
|
||||
if(len){
|
||||
//attribute position fixed
|
||||
for(var i = 0;i<len;i++){
|
||||
var a = el[i];
|
||||
position(a.offset);
|
||||
a.offset = copyLocator(locator,{});
|
||||
}
|
||||
}
|
||||
position(end);
|
||||
}
|
||||
|
||||
if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
|
||||
el.closed = true;
|
||||
if(!entityMap.nbsp){
|
||||
errorHandler.warning('unclosed xml attribute');
|
||||
}
|
||||
}
|
||||
appendElement(el,domBuilder,parseStack);
|
||||
if(locator && len){
|
||||
var locator2 = copyLocator(locator,{});
|
||||
//try{//attribute position fixed
|
||||
for(var i = 0;i<len;i++){
|
||||
var a = el[i];
|
||||
position(a.offset);
|
||||
a.locator = copyLocator(locator,{});
|
||||
}
|
||||
//}catch(e){console.error('@@@@@'+e)}
|
||||
domBuilder.locator = locator2
|
||||
if(appendElement(el,domBuilder,currentNSMap)){
|
||||
parseStack.push(el)
|
||||
}
|
||||
domBuilder.locator = locator;
|
||||
}else{
|
||||
if(appendElement(el,domBuilder,currentNSMap)){
|
||||
parseStack.push(el)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(el.uri === 'http://www.w3.org/1999/xhtml' && !el.closed){
|
||||
@ -160,8 +187,10 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
||||
}
|
||||
}
|
||||
}catch(e){
|
||||
errorHandler.error('element parse error: '+e);
|
||||
errorHandler.error('element parse error: '+e)
|
||||
//errorHandler.error('element parse error: '+e);
|
||||
end = -1;
|
||||
//throw e;
|
||||
}
|
||||
if(end>start){
|
||||
start = end;
|
||||
@ -181,7 +210,7 @@ function copyLocator(f,t){
|
||||
* @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
|
||||
* @return end of the elementStartPart(end of elementEndPart for selfClosed el)
|
||||
*/
|
||||
function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
|
||||
var attrName;
|
||||
var value;
|
||||
var p = ++start;
|
||||
@ -193,7 +222,7 @@ function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
if(s === S_ATTR){//attrName
|
||||
attrName = source.slice(start,p);
|
||||
s = S_EQ;
|
||||
}else if(s === S_ATTR_S){
|
||||
}else if(s === S_ATTR_SPACE){
|
||||
s = S_EQ;
|
||||
}else{
|
||||
//fatalError: equal must after attrName or space after attrName
|
||||
@ -202,25 +231,30 @@ function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
break;
|
||||
case '\'':
|
||||
case '"':
|
||||
if(s === S_EQ){//equal
|
||||
if(s === S_EQ || s === S_ATTR //|| s == S_ATTR_SPACE
|
||||
){//equal
|
||||
if(s === S_ATTR){
|
||||
errorHandler.warning('attribute value must after "="')
|
||||
attrName = source.slice(start,p)
|
||||
}
|
||||
start = p+1;
|
||||
p = source.indexOf(c,start)
|
||||
if(p>0){
|
||||
value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
|
||||
el.add(attrName,value,start-1);
|
||||
s = S_E;
|
||||
s = S_ATTR_END;
|
||||
}else{
|
||||
//fatalError: no end quot match
|
||||
throw new Error('attribute value no end \''+c+'\' match');
|
||||
}
|
||||
}else if(s == S_V){
|
||||
}else if(s == S_ATTR_NOQUOT_VALUE){
|
||||
value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
|
||||
//console.log(attrName,value,start,p)
|
||||
el.add(attrName,value,start);
|
||||
//console.dir(el)
|
||||
errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
|
||||
start = p+1;
|
||||
s = S_E
|
||||
s = S_ATTR_END
|
||||
}else{
|
||||
//fatalError: no equal before
|
||||
throw new Error('attribute value must after "="');
|
||||
@ -230,14 +264,14 @@ function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
switch(s){
|
||||
case S_TAG:
|
||||
el.setTagName(source.slice(start,p));
|
||||
case S_E:
|
||||
case S_S:
|
||||
case S_C:
|
||||
s = S_C;
|
||||
case S_ATTR_END:
|
||||
case S_TAG_SPACE:
|
||||
case S_TAG_CLOSE:
|
||||
s =S_TAG_CLOSE;
|
||||
el.closed = true;
|
||||
case S_V:
|
||||
case S_ATTR_NOQUOT_VALUE:
|
||||
case S_ATTR:
|
||||
case S_ATTR_S:
|
||||
case S_ATTR_SPACE:
|
||||
break;
|
||||
//case S_EQ:
|
||||
default:
|
||||
@ -247,30 +281,36 @@ function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
case ''://end document
|
||||
//throw new Error('unexpected end of input')
|
||||
errorHandler.error('unexpected end of input');
|
||||
if(s == S_TAG){
|
||||
el.setTagName(source.slice(start,p));
|
||||
}
|
||||
return p;
|
||||
case '>':
|
||||
switch(s){
|
||||
case S_TAG:
|
||||
el.setTagName(source.slice(start,p));
|
||||
case S_E:
|
||||
case S_S:
|
||||
case S_C:
|
||||
case S_ATTR_END:
|
||||
case S_TAG_SPACE:
|
||||
case S_TAG_CLOSE:
|
||||
break;//normal
|
||||
case S_V://Compatible state
|
||||
case S_ATTR_NOQUOT_VALUE://Compatible state
|
||||
case S_ATTR:
|
||||
value = source.slice(start,p);
|
||||
if(value.slice(-1) === '/'){
|
||||
el.closed = true;
|
||||
value = value.slice(0,-1)
|
||||
}
|
||||
case S_ATTR_S:
|
||||
if(s === S_ATTR_S){
|
||||
case S_ATTR_SPACE:
|
||||
if(s === S_ATTR_SPACE){
|
||||
value = attrName;
|
||||
}
|
||||
if(s == S_V){
|
||||
if(s == S_ATTR_NOQUOT_VALUE){
|
||||
errorHandler.warning('attribute "'+value+'" missed quot(")!!');
|
||||
el.add(attrName,value.replace(/&#?\w+;/g,entityReplacer),start)
|
||||
}else{
|
||||
if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !value.match(/^(?:disabled|checked|selected)$/i)){
|
||||
errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
|
||||
}
|
||||
el.add(value,value,start)
|
||||
}
|
||||
break;
|
||||
@ -287,64 +327,68 @@ function parseElementStartPart(source,start,el,entityReplacer,errorHandler){
|
||||
switch(s){
|
||||
case S_TAG:
|
||||
el.setTagName(source.slice(start,p));//tagName
|
||||
s = S_S;
|
||||
s = S_TAG_SPACE;
|
||||
break;
|
||||
case S_ATTR:
|
||||
attrName = source.slice(start,p)
|
||||
s = S_ATTR_S;
|
||||
s = S_ATTR_SPACE;
|
||||
break;
|
||||
case S_V:
|
||||
case S_ATTR_NOQUOT_VALUE:
|
||||
var value = source.slice(start,p).replace(/&#?\w+;/g,entityReplacer);
|
||||
errorHandler.warning('attribute "'+value+'" missed quot(")!!');
|
||||
el.add(attrName,value,start)
|
||||
case S_E:
|
||||
s = S_S;
|
||||
case S_ATTR_END:
|
||||
s = S_TAG_SPACE;
|
||||
break;
|
||||
//case S_S:
|
||||
//case S_TAG_SPACE:
|
||||
//case S_EQ:
|
||||
//case S_ATTR_S:
|
||||
//case S_ATTR_SPACE:
|
||||
// void();break;
|
||||
//case S_C:
|
||||
//case S_TAG_CLOSE:
|
||||
//ignore warning
|
||||
}
|
||||
}else{//not space
|
||||
//S_TAG, S_ATTR, S_EQ, S_V
|
||||
//S_ATTR_S, S_E, S_S, S_C
|
||||
//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
|
||||
//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
|
||||
switch(s){
|
||||
//case S_TAG:void();break;
|
||||
//case S_ATTR:void();break;
|
||||
//case S_V:void();break;
|
||||
case S_ATTR_S:
|
||||
errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead!!')
|
||||
//case S_ATTR_NOQUOT_VALUE:void();break;
|
||||
case S_ATTR_SPACE:
|
||||
var tagName = el.tagName;
|
||||
if(currentNSMap[''] !== 'http://www.w3.org/1999/xhtml' || !attrName.match(/^(?:disabled|checked|selected)$/i)){
|
||||
errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
|
||||
}
|
||||
el.add(attrName,attrName,start);
|
||||
start = p;
|
||||
s = S_ATTR;
|
||||
break;
|
||||
case S_E:
|
||||
case S_ATTR_END:
|
||||
errorHandler.warning('attribute space is required"'+attrName+'"!!')
|
||||
case S_S:
|
||||
case S_TAG_SPACE:
|
||||
s = S_ATTR;
|
||||
start = p;
|
||||
break;
|
||||
case S_EQ:
|
||||
s = S_V;
|
||||
s = S_ATTR_NOQUOT_VALUE;
|
||||
start = p;
|
||||
break;
|
||||
case S_C:
|
||||
case S_TAG_CLOSE:
|
||||
throw new Error("elements closed character '/' and '>' must be connected to");
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end outer switch
|
||||
//console.log('p++',p)
|
||||
p++;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return end of the elementStartPart(end of elementEndPart for selfClosed el)
|
||||
* @return true if has new namespace define
|
||||
*/
|
||||
function appendElement(el,domBuilder,parseStack){
|
||||
function appendElement(el,domBuilder,currentNSMap){
|
||||
var tagName = el.tagName;
|
||||
var localNSMap = null;
|
||||
var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
|
||||
//var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
|
||||
var i = el.length;
|
||||
while(i--){
|
||||
var a = el[i];
|
||||
@ -383,7 +427,7 @@ function appendElement(el,domBuilder,parseStack){
|
||||
if(prefix === 'xml'){
|
||||
a.uri = 'http://www.w3.org/XML/1998/namespace';
|
||||
}if(prefix !== 'xmlns'){
|
||||
a.uri = currentNSMap[prefix]
|
||||
a.uri = currentNSMap[prefix || '']
|
||||
|
||||
//{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
|
||||
}
|
||||
@ -412,7 +456,8 @@ function appendElement(el,domBuilder,parseStack){
|
||||
}else{
|
||||
el.currentNSMap = currentNSMap;
|
||||
el.localNSMap = localNSMap;
|
||||
parseStack.push(el);
|
||||
//parseStack.push(el);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
|
||||
@ -442,7 +487,11 @@ function fixSelfClosed(source,elStartEnd,tagName,closeMap){
|
||||
var pos = closeMap[tagName];
|
||||
if(pos == null){
|
||||
//console.log(tagName)
|
||||
pos = closeMap[tagName] = source.lastIndexOf('</'+tagName+'>')
|
||||
pos = source.lastIndexOf('</'+tagName+'>')
|
||||
if(pos<elStartEnd){//忘记闭合
|
||||
pos = source.lastIndexOf('</'+tagName)
|
||||
}
|
||||
closeMap[tagName] =pos
|
||||
}
|
||||
return pos<elStartEnd;
|
||||
//}
|
||||
@ -533,7 +582,7 @@ ElementAttributes.prototype = {
|
||||
},
|
||||
length:0,
|
||||
getLocalName:function(i){return this[i].localName},
|
||||
getOffset:function(i){return this[i].offset},
|
||||
getLocator:function(i){return this[i].locator},
|
||||
getQName:function(i){return this[i].qName},
|
||||
getURI:function(i){return this[i].uri},
|
||||
getValue:function(i){return this[i].value}
|
||||
@ -580,7 +629,5 @@ function split(source,start){
|
||||
}
|
||||
}
|
||||
|
||||
if(typeof require == 'function'){
|
||||
exports.XMLReader = XMLReader;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,15 @@
|
||||
},
|
||||
"prefix": "",
|
||||
"suffix": ""
|
||||
},{
|
||||
"file": "entities.js",
|
||||
"fields": {
|
||||
"type": "application/javascript",
|
||||
"title": "$:/plugins/tiddlywiki/xmldom/entities",
|
||||
"module-type": "library"
|
||||
},
|
||||
"prefix": "",
|
||||
"suffix": ""
|
||||
},{
|
||||
"file": "sax.js",
|
||||
"fields": {
|
||||
|
Loading…
Reference in New Issue
Block a user