Skip to content

Commit 2599e36

Browse files
committed
add new Nodes
1 parent 32bca80 commit 2599e36

15 files changed

+425
-216
lines changed

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
rootProject.name = "HtmlToComposeWeb"
2+
rootProject.name = "HtmlToComposeWebConverter"
33

src/main/kotlin/FormNode.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import org.jsoup.nodes.Attribute
2+
import org.jsoup.nodes.Element
3+
4+
class FormNode(private val element: Element) : MyNode {
5+
6+
override fun print(): String {
7+
8+
var str = "Form ("
9+
val actionValue = element.attributes().get("action")
10+
element.attributes().remove("action")
11+
12+
val attributesList: MutableList<Attribute> = element.attributes().asList()
13+
14+
val attrText = printAttributes(attributesList)
15+
str += attrText
16+
17+
if (actionValue.isNotBlank()) {
18+
if (attrText.isNotBlank()) {
19+
str += (", ")
20+
}
21+
}
22+
str += ("action = \"${actionValue}\"")
23+
str += (")")
24+
25+
val childNodesText = element.childNodes().joinToString(separator = "") {
26+
getMyNode(it).print()
27+
}
28+
29+
str += "{"
30+
if (childNodesText.isNotBlank()) {
31+
str += "\n"
32+
}
33+
str += childNodesText
34+
if (childNodesText.isNotBlank()) {
35+
str += "\n"
36+
}
37+
str += ("}\n")
38+
return str
39+
}
40+
41+
}

src/main/kotlin/GenericNode.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import org.jsoup.nodes.Element
2+
3+
class GenericNode(private val element: Element) : MyNode {
4+
5+
override fun print(): String {
6+
var str = "\n"+element.tag().toString().capitalize() + " "
7+
8+
val attrs = printAttributes(element.attributes().asList())
9+
if (attrs.isNotBlank()) {
10+
str += "($attrs)"
11+
}
12+
13+
14+
val childNodesText = element.childNodes().joinToString(separator = "") {
15+
getMyNode(it).print()
16+
}
17+
18+
str += "{"
19+
if(childNodesText.isNotBlank()){
20+
str += "\n"
21+
}
22+
str += childNodesText
23+
if(childNodesText.isNotBlank()){
24+
str += "\n"
25+
}
26+
str += ("}\n")
27+
return str
28+
}
29+
}

src/main/kotlin/ImgNode.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import org.jsoup.nodes.Attribute
2+
import org.jsoup.nodes.Element
3+
4+
class ImgNode(val element: Element) : MyNode {
5+
6+
override fun print(): String {
7+
8+
var str = "Img ("
9+
val altValue = element.attributes().get("alt")
10+
element.attributes().remove("alt")
11+
val srcValue = element.attributes().get("src")
12+
element.attributes().remove("src")
13+
14+
val attributesList: MutableList<Attribute> = element.attributes().asList()
15+
16+
val attrText = printAttributes(attributesList)
17+
str += (attrText)
18+
if (attrText.isNotBlank()) {
19+
str += (", ")
20+
}
21+
str += ("src = \"${srcValue}\"")
22+
str += (", alt = \"${altValue}\"")
23+
str += (")")
24+
25+
return str
26+
}
27+
28+
}

src/main/kotlin/InputNode.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import org.jsoup.nodes.Element
2+
3+
class InputNode(private val element: Element) : MyNode {
4+
5+
override fun print(): String {
6+
var str = "Input ("
7+
val hasType = element.attributes().get("type")
8+
element.attributes().remove("type")
9+
val attrText = printAttributes(element.attributes().asList())
10+
str += attrText
11+
12+
if (hasType.isNotBlank()) {
13+
if (attrText.isNotBlank()) {
14+
str += (", ")
15+
}
16+
val type = hasType.capitalize()
17+
str += ("type = InputType.${type}")
18+
}
19+
20+
str += ")"
21+
return (str)
22+
}
23+
24+
}

src/main/kotlin/LabelNode.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import org.jsoup.nodes.Attribute
2+
import org.jsoup.nodes.Element
3+
4+
class LabelNode(private val element: Element) : MyNode {
5+
6+
override fun print(): String {
7+
8+
var str = "Label ("
9+
val forValue = element.attributes().get("for")
10+
element.attributes().remove("for")
11+
12+
val attributesList: MutableList<Attribute> = element.attributes().asList()
13+
14+
val attrText = printAttributes(attributesList)
15+
str += attrText
16+
17+
if(forValue.isNotBlank()){
18+
if (attrText.isNotBlank()) {
19+
str += (", ")
20+
}
21+
}
22+
str += ("forId = \"${forValue}\"")
23+
24+
str += (")")
25+
26+
val childNodesText = element.childNodes().joinToString(separator = "") {
27+
getMyNode(it).print()
28+
}
29+
30+
str += "{"
31+
if(childNodesText.isNotBlank()){
32+
str += "\n"
33+
}
34+
str += childNodesText
35+
if(childNodesText.isNotBlank()){
36+
str += "\n"
37+
}
38+
str += ("}\n")
39+
return str
40+
}
41+
42+
}

0 commit comments

Comments
 (0)