Skip to content

Commit b7e98a6

Browse files
committed
add option to disable in table text foster parenting
1 parent a8ab13a commit b7e98a6

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

src/main/java/ch/digitalfondue/jfiveparse/Option.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,6 @@ public enum Option {
9393
* When encountering unknown self-closing tag, will interpret as self-closing tag instead of ignoring.
9494
*/
9595
INTERPRET_SELF_CLOSING_ANYTHING_ELSE,
96+
97+
DISABLE_IN_TABLE_TEXT_FOSTER_PARENTING
9698
}

src/main/java/ch/digitalfondue/jfiveparse/Parser.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class Parser {
2929
private final boolean transformEntities;
3030
private final boolean disableIgnoreTokenInBodyStartTag;
3131
private final boolean interpretSelfClosingAnythingElse;
32+
private final boolean disableInTableTextForsterParenting;
3233

3334
/**
3435
* Instantiate a parser with the default configuration.
@@ -42,6 +43,7 @@ public Parser() {
4243
transformEntities = true;
4344
disableIgnoreTokenInBodyStartTag = false;
4445
interpretSelfClosingAnythingElse = false;
46+
disableInTableTextForsterParenting = false;
4547
}
4648

4749
/**
@@ -52,6 +54,7 @@ public Parser() {
5254
* <li>{@link Option#DONT_TRANSFORM_ENTITIES}</li>
5355
* <li>{@link Option#DISABLE_IGNORE_TOKEN_IN_BODY_START_TAG}</li>
5456
* <li>{@link Option#INTERPRET_SELF_CLOSING_ANYTHING_ELSE}</li>
57+
* <li>{@link Option#DISABLE_IN_TABLE_TEXT_FOSTER_PARENTING}</li>
5558
* </ul>
5659
*
5760
* @param options
@@ -61,6 +64,7 @@ public Parser(Set<Option> options) {
6164
this.transformEntities = !options.contains(Option.DONT_TRANSFORM_ENTITIES);
6265
this.disableIgnoreTokenInBodyStartTag = options.contains(Option.DISABLE_IGNORE_TOKEN_IN_BODY_START_TAG);
6366
this.interpretSelfClosingAnythingElse = options.contains(Option.INTERPRET_SELF_CLOSING_ANYTHING_ELSE);
67+
this.disableInTableTextForsterParenting = options.contains(Option.DISABLE_IN_TABLE_TEXT_FOSTER_PARENTING);
6468
}
6569

6670
/**
@@ -115,7 +119,7 @@ private List<Node> parseFragment(ProcessedInputStream is, Element node) {
115119

116120
// 1 when creating a tree constructor, a document is automatically
117121
// created (good idea? y/n?)
118-
TreeConstructor tokenHandler = new TreeConstructor(disableIgnoreTokenInBodyStartTag, interpretSelfClosingAnythingElse);
122+
TreeConstructor tokenHandler = new TreeConstructor(disableIgnoreTokenInBodyStartTag, interpretSelfClosingAnythingElse , disableInTableTextForsterParenting);
119123
//
120124
tokenHandler.isHtmlFragmentParsing = true;
121125
tokenHandler.scriptingFlag = scriptingFlag;
@@ -187,7 +191,11 @@ private static Element getFirstFormElementFrom(Node node) {
187191
}
188192

189193
private Document parse(ProcessedInputStream is) {
190-
TreeConstructor tokenHandler = new TreeConstructor(disableIgnoreTokenInBodyStartTag, interpretSelfClosingAnythingElse);
194+
TreeConstructor tokenHandler = new TreeConstructor(
195+
disableIgnoreTokenInBodyStartTag,
196+
interpretSelfClosingAnythingElse,
197+
disableInTableTextForsterParenting
198+
);
191199
tokenHandler.scriptingFlag = scriptingFlag;
192200
Tokenizer tokenizer = new Tokenizer(tokenHandler, transformEntities);
193201
tokenHandler.setTokenizer(tokenizer);

src/main/java/ch/digitalfondue/jfiveparse/TreeConstructor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class TreeConstructor {
5353

5454
final boolean disableIgnoreTokenInBodyStartTag;
5555
final boolean interpretSelfClosingAnythingElse;
56+
final boolean disableInTableTextForsterParenting;
5657

5758
// ----
5859
private int tokenType;
@@ -107,9 +108,10 @@ void setTokenizer(Tokenizer tokenizer) {
107108
this.tokenizer = tokenizer;
108109
}
109110

110-
TreeConstructor(boolean disableIgnoreTokenInBodyStartTag, boolean interpretSelfClosingAnythingElse) {
111+
TreeConstructor(boolean disableIgnoreTokenInBodyStartTag, boolean interpretSelfClosingAnythingElse, boolean disableInTableTextForsterParenting) {
111112
this.disableIgnoreTokenInBodyStartTag = disableIgnoreTokenInBodyStartTag;
112113
this.interpretSelfClosingAnythingElse = interpretSelfClosingAnythingElse;
114+
this.disableInTableTextForsterParenting = disableInTableTextForsterParenting;
113115
}
114116

115117
private void setTagNameAndSaveOriginal(ResizableCharBuilder rawTagName) {

src/main/java/ch/digitalfondue/jfiveparse/TreeConstructorInTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static void inTableText(int tokenType, String tagName, int tagNameID, TreeConstr
243243
treeConstructor.appendToPendingTableCharactersToken(chr);
244244
} else {
245245
ResizableCharBuilder chars = treeConstructor.getPendingTableCharactersToken();
246-
if (!isAllSpaceCharacters(chars)) {
246+
if (!isAllSpaceCharacters(chars) && !treeConstructor.disableInTableTextForsterParenting) {
247247
// TODO CHECK
248248

249249
treeConstructor.emitParseError();

src/test/java/ch/digitalfondue/jfiveparse/TokenSaver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TokenSaver extends TreeConstructor {
2525
final List<Token> tokens = new ArrayList<>();
2626

2727
public TokenSaver() {
28-
super(false, false);
28+
super(false, false, false);
2929
}
3030

3131
@Override

0 commit comments

Comments
 (0)