📄 de_xhtml.js
字号:
bSetRequired = true;
}
aRet[ci] += "/>";
}
bAddEndSlash = false;
}
if (aRet[ci] != '') {
ci++;
}
aType[ci] = 3; // Text
aRet[ci] = '';
break;
}
if (iMode == 2 || iMode == 4) {
aRet[ci] += sc;
}
if (iMode == 3) {
iMode = 4;
aRet[ci] += sc;
if (aRet[ci] != '') {
ci++;
}
aType[ci] = 3; // CDATA
aRet[ci] = '';
break;
}
if (iMode == 5) {
iMode = 0;
aRet[ci] += "\"";
if (this._in_array(sRequired, this.aRequiredAttributes)) {
aRet[ci] += " " + this.aRequiredAttributes[sRequired] + "=\"" + this.aRequiredAttributesValues[sRequired] + "\" ";
sRequired = '';
bSetRequired = true;
}
if (bAddEndSlash == false) {
aRet[ci] += ">";
} else {
aRet[ci] += "/>";
}
if (aRet[ci] != '') {
ci++;
}
aType[ci] = 3; // Text
aRet[ci] = '';
break;
}
break;
case "\"":
case "'":
if (iMode == 0) {
if (sc == "'") {
// aRet[ci] += "'";
aRet[ci] += sc;
break;
} else {
aRet[ci] += sc;
// aRet[ci] += """;
break;
}
}
if (iMode == 1) {
sAttributeChar = sc;
iMode = 2;
aRet[ci] += sc;
break;
}
if (iMode == 2) {
if (bInEscape == true) {
bInEscape = false;
aRet[ci] += sc;
break;
} else {
aRet[ci] += sc;
if (sAttributeChar == sc) {
iMode = 1;
}
break;
}
}
if (iMode == 4 || iMode == 3) {
aRet[ci] += sc;
}
break;
case "\\":
aRet[ci] += sc;
//if (iMode == 2) {
// bInEscape = true;
// aRet[ci] += sc;
// }
break;
case " ":
if (iMode == 5) {
iMode = 1;
aRet[ci] += "\"" + sc;
break;
}
aRet[ci] += sc;
break;
case "&":
var t = 1;
var nc = this.sHTML.charCodeAt(i+t);
while (((nc > 96 && nc < 123) || (nc > 64 && nc < 91) || (nc > 47 && nc < 58)) && t < il) {
t++;
nc = this.sHTML.charCodeAt(i+t);
}
var nw = this.sHTML.substr(i, t).toLowerCase();
nw += ";";
if (this._in_array(nw, aEntities)) {
aRet[ci] += aEntities[nw];
i = i + nw.length - 1;
break;
} else {
if (iMode == 4) {
aRet[ci] += "&";
} else {
aRet[ci] += "&";
}
}
//aRet[ci] += "&";
break;
case "=": // Fix an attribute if there are no " or ' used...
if (iMode == 1) {
var t = 1;
var nc = this.sHTML.charCodeAt(i+t);
while (nc == 32) {
t++;
nc = this.sHTML.charCodeAt(i+t);
}
i += t - 1;
if (nc != 34 && nc != 39) {
aRet[ci] += sc + "\"";
iMode = 5;
break;
}
}
aRet[ci] += sc;
break;
default:
if (bInEscape == true) {
bInEscape = false;
}
if (iMode == 1) {
var t = 1;
var nc = this.sHTML.charCodeAt(i+t);
while (((nc > 96 && nc < 123) || (nc > 64 && nc < 91) || (nc > 47 && nc < 58)) && t < il) {
t++;
nc = this.sHTML.charCodeAt(i+t);
}
var nw = this.sHTML.substr(i, t).toLowerCase();
if (this._in_array(aTagNames[ci], this.aRequiredAttributes) && (aType[ci] == 0 || aType[ci] == 2)) {
if (bSetRequired == true) {
sRequired = aTagNames[ci];
}
if (this.aRequiredAttributes[aTagNames[ci]] == nw) {
sRequired = '';
bSetRequired = false;
}
}
if (this._in_array(nw, this.aEmptyAttributes)) {
aRet[ci] = aRet[ci] + nw + "=\"" + nw + "\"";
i = i + nw.length - 1;
break;
} else {
aRet[ci] = aRet[ci] + nw;
i = i + nw.length - 1;
break;
}
}
if (iMode == 3) {
aRet[ci] += sc.toLowerCase();
} else {
aRet[ci] += sc;
}
break;
}
}
this.aTypes = aType;
this.aTagNames = aTagNames;
return (aRet);
}
/**
* Filter the tag name from a string
*
* @access public
* @param string - s - The input string
* @return string
*
* @author Jorgen Horstink <jorgen@webstores.nl>
* @time 27-08-2003 => 10 minutes
* 28-08-2003 => 10 minutes => I made some speed improvements
*/
this.tagName = function (s) {
var t = 1;
// If the second char is a slash, remove that slash from the string
if (s.charCodeAt(1) == 47) {
s = "<" + s.substr(2);
}
var c = s.charCodeAt(t);
var sl = s.length;
while (((c > 96 && c < 123) || (c > 64 && c < 91) || (c > 47 && c < 58)) && t < sl) {
t++;
c = s.charCodeAt(t);
}
return (s.substr(1, t - 1).toLowerCase());
}
/**
* Sets a parameter for the Class
*
* @access public
* @param sType - The name of the param to set
* @param sValue - The value of that param
* @return void
*
* @author Jorgen Horstink
* @time: 28-08-2003 => 5 minutes
*/
this.setParam = function (sType, sValue) {
switch (sType.toLowerCase()) {
case 'html':
this.sHTML = sValue;
break;
case 'emptyattributes':
this.aEmptyAttributes = sValue;
break;
case 'tags':
this.aTags = sValue;
break;
case 'emptytags':
this.aEmptyTags = sValue;
break;
case 'nonestedtags':
this.aNoNestedTags = sValue;
break;
case 'removeemptytags':
this.aRemoveEmptyTags = sValue;
break;
case 'entities':
this.aEntities = sValue;
break;
case 'requiredattributes':
this.aRequiredAttributes = sValue;
break;
case 'requiredattributesvalues':
this.aRequiredAttributesValues = sValue;
break;
}
}
/**
* Gets a parameter from the Class
*
* @access public
* @param sType - The name of the param to retrieve
* @return mixed
*
* @author Jorgen Horstink
* @time: 28-08-2003 => 5 minutes
*/
this.getParam = function (sType) {
switch (sType.toLowerCase()) {
case 'html':
return (this.sHTML);
}
}
///////////////////////
// Private functions //
///////////////////////
/**
* Checks whether or not a value exists in an Array
*
* @access public
* @param string - needle - The string to search for
* @param array - haystack - The Array where to look in
* @return boolen
*
* @author Jorgen Horstink <jorgen@webstores.nl>
* @time 27-08-2003 => 5 minutes
*/
/* Old function that is 25% slower!
this._in_array = function (needle, haystack) {
var il = haystack.length;
for (var i = 0; i < il; i++) {
if (needle == haystack[i]) {
// The needle is found in the Array, so return true
return (true);
}
}
// The needle is not found, so return False
return (false);
}*/
this._in_array = function (needle, haystack) {
return (haystack[needle] != null);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -