Skip to content

Commit 0aed83b

Browse files
committed
- Added isClosed attribute to the Element class
- Fixed bug in the HTML Parser to deal with comments that end with ">-->" git-svn-id: svn://192.168.0.80/JavaXT/javaxt-core@1442 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent 0e0f052 commit 0aed83b

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/javaxt/html/Element.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class Element {
1616
private String innerHTML;
1717
private String outerHTML;
1818
private Parser parser;
19+
private boolean isClosed;
1920

2021

2122
//**************************************************************************
@@ -70,9 +71,22 @@ public Element(String outerHTML) throws Exception {
7071

7172
//Set innerHTML
7273
innerHTML = outerHTML.substring(gt);
73-
if (innerHTML.trim().length()>0){
74+
if (innerHTML.trim().length()>0){ //has inner html
75+
7476
int idx = innerHTML.lastIndexOf("</" + nodeName);
75-
if (idx>-1) innerHTML = innerHTML.substring(0, idx);
77+
if (idx>-1){
78+
innerHTML = innerHTML.substring(0, idx);
79+
isClosed = true;
80+
}
81+
else{
82+
isClosed = false;
83+
}
84+
}
85+
else{ //no inner html
86+
87+
//Check if the tag is self enclosing (e.g. "<hr/>")
88+
char c = outerHTML.charAt(gt-2); //character immediately before ">"
89+
isClosed = c=='/';
7690
}
7791
}
7892

@@ -98,6 +112,16 @@ public String getAttributes(){
98112
}
99113

100114

115+
//**************************************************************************
116+
//** isClosed
117+
//**************************************************************************
118+
/** Returns true if the element has a closing tag or is self closing
119+
*/
120+
public boolean isClosed(){
121+
return isClosed;
122+
}
123+
124+
101125
//**************************************************************************
102126
//** getInnerHTML
103127
//**************************************************************************

src/javaxt/html/Parser.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package javaxt.html;
22
import java.util.ArrayList;
3+
import static javaxt.utils.Console.console;
34

45
//******************************************************************************
56
//** HTML Parser
@@ -467,9 +468,9 @@ private static int findEndTag(String tagName, int x, String s){
467468
int len = s.length();
468469
for (int i=x; i<len; i++){
469470
char c = s.charAt(i);
471+
char p = s.charAt(i-1);
470472

471-
472-
if (isBlank(c) || i==len-1 || (c=='<' && s.charAt(i-1)=='>')){
473+
if (isBlank(c) || i==len-1 || (c=='<' && p=='>') || (c=='-' && p=='>')){
473474

474475
if (start>-1){
475476
String str = s.substring(start, i);
@@ -546,12 +547,20 @@ else if (tag.equals(tagName)){
546547
numTags++;
547548
}
548549
}
550+
else{
551+
552+
553+
//Hacky solution for comments that end with ">-->"
554+
if (tagName.equals("--") && tag.equals("-")){
555+
foundMatch = true;
556+
numTags--;
557+
}
558+
}
549559

550560
}
551561
}
552562

553563

554-
555564
// console.log("tag2:", tag, numTags, foundMatch);
556565

557566

0 commit comments

Comments
 (0)