diff options
author | JJ | 2022-12-29 02:07:29 +0000 |
---|---|---|
committer | JJ | 2022-12-29 02:20:51 +0000 |
commit | 595853ad76bbebf74a9a737870d5a89fb9f21f55 (patch) | |
tree | bb0f0dc491696519c3a5eae9a89087b7b626a004 /src/main/model/html | |
parent | ddf614b732649875f20b54af3ef622c5c39127ff (diff) |
Rework layout generator
Diffstat (limited to 'src/main/model/html')
-rw-r--r-- | src/main/model/html/HtmlParser.java | 22 | ||||
-rw-r--r-- | src/main/model/html/TextNode.java | 1 |
2 files changed, 12 insertions, 11 deletions
diff --git a/src/main/model/html/HtmlParser.java b/src/main/model/html/HtmlParser.java index a3abe0f..6e015ae 100644 --- a/src/main/model/html/HtmlParser.java +++ b/src/main/model/html/HtmlParser.java @@ -60,8 +60,6 @@ public class HtmlParser { public ArrayList<Node> parseHtml(String input) { for (char c : input.toCharArray()) { - // System.out.print(state); - // System.out.println(" " + c + " " + currentText); switch (state) { case HTML -> caseHtml(c); case UNKNOWN_TAG -> caseUnknownTag(c); @@ -85,7 +83,7 @@ public class HtmlParser { addNewTextNode(); } } - case ' ', '\n' -> { + case ' ', '\t', '\n' -> { if (previousChar != ' ') { currentText += ' '; } @@ -125,7 +123,7 @@ public class HtmlParser { private void caseOpeningTag(char c) { switch (c) { case '>' -> addNewElementNode(); - case ' ', '\n' -> state = ParserState.KEY; + case ' ', '\t', '\n' -> state = ParserState.KEY; default -> currentTag += c; } } @@ -142,7 +140,7 @@ public class HtmlParser { } currentTag = ""; } - case ' ', '\n' -> {} + case ' ', '\t', '\n' -> {} default -> currentTag += c; } } @@ -151,7 +149,7 @@ public class HtmlParser { switch (c) { case '>' -> addNewElementNode(); case '=' -> state = ParserState.VALUE; - case ' ', '\n' -> {} + case ' ', '\t', '\n' -> {} default -> currentKey += c; } } @@ -160,7 +158,7 @@ public class HtmlParser { switch (c) { case '\'' -> state = ParserState.SINGLE_QUOTES; case '\"' -> state = ParserState.DOUBLE_QUOTES; - case ' ', '\n' -> { + case ' ', '\t', '\n' -> { state = ParserState.KEY; currentAttributes.add(new Pair<>(currentKey, currentValue)); currentKey = ""; @@ -237,10 +235,12 @@ public class HtmlParser { // Helper function to check method length boxes. private void addNewTextNode() { - if (unfinished.size() != 0) { - unfinished.getLast().children.add(new TextNode(currentText)); - } else { - result.add(new TextNode(currentText)); + if (!currentText.equals(" ")) { // fixme + if (unfinished.size() != 0) { + unfinished.getLast().children.add(new TextNode(currentText)); + } else { + result.add(new TextNode(currentText)); + } } currentText = ""; previousChar = '\0'; diff --git a/src/main/model/html/TextNode.java b/src/main/model/html/TextNode.java index 29f2791..cebf854 100644 --- a/src/main/model/html/TextNode.java +++ b/src/main/model/html/TextNode.java @@ -4,6 +4,7 @@ package model.html; * This TextNode class represents raw text, with no nested tags. */ public record TextNode(String text) implements Node { + // We implement this method for easy debugging. public String data() { return text(); |