Skip to content

Commit 92b5a1a

Browse files
committed
preserve case for tags and attributes.
1 parent 18f2481 commit 92b5a1a

File tree

2 files changed

+12
-5
lines changed
  • converter/src

2 files changed

+12
-5
lines changed

converter/src/main/kotlin/de/jensklingenberg/htmltocfw/converter/Main.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package de.jensklingenberg.htmltocfw.converter
22

33
import de.jensklingenberg.htmltocfw.converter.node.getMyNode
44
import org.jsoup.Jsoup
5+
import org.jsoup.parser.ParseSettings
56
import org.jsoup.parser.Parser
67
import java.io.File
78

@@ -18,7 +19,9 @@ fun main() {
1819
}
1920

2021
fun htmlToCompose(html: String): String {
21-
val doc = Jsoup.parse(html, Parser.xmlParser());
22+
val parser = Parser.htmlParser();
23+
parser.settings(ParseSettings(true, true))
24+
val doc = parser.parseInput(html,"")
2225

2326
return doc.body().childNodes().joinToString(separator = "") {
2427
getMyNode(it).print()

converter/src/test/kotlin/myTest.kt renamed to converter/src/test/kotlin/MyTest.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import de.jensklingenberg.htmltocfw.converter.getMyNode
21
import de.jensklingenberg.htmltocfw.converter.htmlToCompose
2+
import de.jensklingenberg.htmltocfw.converter.node.getMyNode
33
import org.jsoup.Jsoup
44
import org.junit.jupiter.api.Test
55
import kotlin.test.assertEquals
66

7-
class myTest {
7+
class MyTest {
88

99
@Test
1010
fun ButtonTest(){
@@ -15,6 +15,7 @@ class myTest {
1515
attr("onclick","alert('Hello world!')")
1616
}){
1717
Text("Click Me!")
18+
1819
}
1920
2021
""".trimIndent()
@@ -34,6 +35,7 @@ class myTest {
3435
attr("width","500")
3536
attr("height","600")
3637
}, src = "img_girl.jpg", alt = "Girl in a jacket")
38+
3739
""".trimIndent()
3840

3941
val text = doc.body().childNodes().joinToString(separator = "") {
@@ -45,10 +47,11 @@ class myTest {
4547

4648
@Test
4749
fun nodeATest(){
48-
val html = """ <a href="https://www.w3schools.com">Visit W3Schools.com!</a> """
50+
val html = """<a href="https://www.w3schools.com">Visit W3Schools.com!</a> """
4951
val exp = """
5052
A (href = "https://www.w3schools.com"){
5153
Text("Visit W3Schools.com!")
54+
5255
}
5356
5457
""".trimIndent()
@@ -60,10 +63,11 @@ class myTest {
6063

6164
@Test
6265
fun failedTest(){
63-
val html = """ a href="https://www.w3schools.com<<">Visit W3Schools.com!</a> """
66+
val html = """ <a href="https://www.w3schools.com">Visit W3Schools.com!</a> """
6467
val exp = """
6568
A (href = "https://www.w3schools.com"){
6669
Text("Visit W3Schools.com!")
70+
6771
}
6872
6973
""".trimIndent()

0 commit comments

Comments
 (0)