File tree Expand file tree Collapse file tree 15 files changed +425
-216
lines changed Expand file tree Collapse file tree 15 files changed +425
-216
lines changed Original file line number Diff line number Diff line change 1
1
2
- rootProject.name = " HtmlToComposeWeb "
2
+ rootProject.name = " HtmlToComposeWebConverter "
3
3
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments