Skip to content

Commit bfcdabe

Browse files
committed
chore: highlightjs support
1 parent 186b6c0 commit bfcdabe

File tree

9 files changed

+72
-50
lines changed

9 files changed

+72
-50
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package dev.suresh
2+
3+
import BuildConfig
4+
import kotlinx.datetime.Clock
5+
import kotlinx.datetime.TimeZone
6+
import kotlinx.datetime.toLocalDateTime
7+
import kotlinx.io.bytestring.*
8+
import kotlinx.serialization.encodeToString
9+
import kotlinx.serialization.json.Json
10+
11+
class Greeting {
12+
13+
val json = Json {
14+
isLenient = true
15+
prettyPrint = true
16+
}
17+
18+
fun greeting() =
19+
"""
20+
| ${BuildConfig.time} - ${KData("Foo", 20, "test")}: Kotlin $platform: ${KotlinVersion.CURRENT}!
21+
| ${kotlinxTests()}
22+
"""
23+
.trimMargin()
24+
25+
private fun kotlinxTests(): String {
26+
val ba = "Kotlinx".encodeToByteArray()
27+
val bs1 = ByteString(ba)
28+
val bs2 = "IO".encodeToByteString()
29+
30+
val bs = buildByteString {
31+
append(bs1)
32+
append(bs2)
33+
}
34+
35+
return """
36+
|${Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())}
37+
|${json.encodeToString(KData("Bar", 22, "test"))}
38+
|${bs.decodeToString()}
39+
"""
40+
.trimMargin()
41+
}
42+
}
Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,3 @@
11
package dev.suresh
22

3-
import BuildConfig
4-
import kotlinx.datetime.Clock
5-
import kotlinx.datetime.TimeZone
6-
import kotlinx.datetime.toLocalDateTime
7-
import kotlinx.io.bytestring.*
8-
import kotlinx.serialization.encodeToString
9-
import kotlinx.serialization.json.Json
10-
113
expect val platform: String
12-
13-
class Greeting {
14-
15-
val json = Json {
16-
isLenient = true
17-
prettyPrint = true
18-
}
19-
20-
fun greeting() =
21-
"""
22-
| ${BuildConfig.time} - ${KData("Foo", 123, "test")}: Kotlin $platform: ${KotlinVersion.CURRENT}!
23-
| ${kotlinxTests()}
24-
"""
25-
.trimMargin()
26-
27-
private fun kotlinxTests(): String {
28-
val ba = "Kotlinx".encodeToByteArray()
29-
val bs1 = ByteString(ba)
30-
val bs2 = "IO".encodeToByteString()
31-
32-
val bs = buildByteString {
33-
append(bs1)
34-
append(bs2)
35-
}
36-
37-
return """
38-
|${Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())}
39-
|${json.encodeToString(KData("Bar", 123, "test"))}
40-
|${bs.decodeToString()}
41-
"""
42-
.trimMargin()
43-
}
44-
}

compose-web/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
### Run Web app
2+
3+
```bash
4+
$ ./gradlew :web:jsBrowserProductionRun -t
5+
```
6+
7+
### Resources
8+
9+
- [Kotlin Multiplatform Package Search](https://package-search.jetbrains.com/search?query=http&onlyMpp=true)
10+
- [Compose Lint Rules](https://slackhq.github.io/compose-lints/rules/)

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ kotlinx.atomicfu.enableJsIrTransformation=true
2222

2323
# MPP
2424
kotlin.mpp.enableCInteropCommonization=true
25+
# kotlin.js.ir.output.granularity=whole-program
2526

2627
# Compose
2728
org.jetbrains.compose.experimental.uikit.enabled=true

gradle/kotlin-js-store/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,11 @@ [email protected]:
13081308
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
13091309
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==
13101310

1311+
1312+
version "11.8.0"
1313+
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-11.8.0.tgz#966518ea83257bae2e7c9a48596231856555bb65"
1314+
integrity sha512-MedQhoqVdr0U6SSnWPzfiadUcDHfN/Wzq25AkXiQv9oiOO/sG0S7XkvpFIqWBl9Yq1UYyYOOVORs5UW2XlPyzg==
1315+
13111316
hpack.js@^2.1.6:
13121317
version "2.1.6"
13131318
resolved "https://registry.yarnpkg.com/hpack.js/-/hpack.js-2.1.6.tgz#87774c0949e513f42e84575b3c45681fade2a0b2"

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ junit = "5.10.0-RC1"
4747
ktor = "2.3.2"
4848
koin = "3.4.1"
4949
kotest = "5.6.2"
50-
ksp-auto-service = "1.0.0"
50+
ksp-auto-service = "1.1.0"
5151
ksp-redacted = "1.6.0"
5252
ksp-powerassert = "0.13.0"
5353
slf4j = "2.0.7"

web/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ dependencies {
2727

2828
jsMainImplementation(projects.common)
2929
jsMainImplementation(libs.kotlinx.html)
30+
jsMainImplementation(npm("highlight.js", "11.8.0"))
3031
// jsMainImplementation(npm("kotlin-playground", "1.28.0"))
31-
// jsMainImplementation(npm("highlight.js", "11.8.0"))
3232
// jsMainImplementation(npm("xterm", "5.2.1"))
3333
// jsMainImplementation(npm("vega-lite", "5.13.0"))
3434
}

web/src/jsMain/kotlin/App.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,26 @@ import kotlinx.html.div
1010
import kotlinx.html.dom.append
1111
import kotlinx.html.dom.create
1212
import kotlinx.html.progress
13+
import org.w3c.dom.HTMLDivElement
1314
import org.w3c.dom.HTMLProgressElement
1415
import org.w3c.dom.Node
1516

1617
suspend fun main() {
1718
val text = Greeting().greeting()
18-
val root = document.getElementById("root")
19+
val root = document.getElementById("root") as HTMLDivElement
1920

2021
text.lines().forEach {
2122
println(it)
22-
root?.appendText(it)
23-
root?.appendChild(document.createElement("br"))
23+
root.appendText(it)
24+
root.appendChild(document.createElement("br"))
2425
}
2526

27+
// HighlightJs.highlightElement(root)
28+
29+
// Javascript Promise
2630
delay(1.seconds)
2731
val promise = Promise.resolve("Promise")
28-
root?.appendText(promise.await())
32+
root.appendText(promise.await())
2933

3034
topLevelJsFun()
3135
runCoroutines()

web/src/jsMain/resources/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"/>
3636

3737
<!-- HighlightJS styles -->
38-
<!-- <link class="codestyle" rel="stylesheet" href="css/hljs/github.min.css">-->
38+
<link class="codestyle" rel="stylesheet" href="css/hljs/github.min.css">
3939
<!-- <link class="codestyle" rel="prefetch alternate stylesheet" href="css/hljs/github-dark.min.css">-->
4040

4141
<!-- Style for XTerm terminal -->
@@ -85,7 +85,7 @@ <h1 class="title">
8585

8686
<div class="card">
8787
<div class="card-content">
88-
<div id="root"></div>
88+
<div id="root" class="language-json"></div>
8989
</div>
9090
</div>
9191
</div>
@@ -104,7 +104,8 @@ <h1 class="title">
104104
<hr>
105105
<p class="subtitle">
106106
<a href="https://kotlinlang.org/docs/coroutines-guide.html">Kotlin Coroutines</a> demo.
107-
Click on progressBar to <mark>cancel</mark>
107+
Click on progress bar to
108+
<mark>cancel</mark>
108109
</p>
109110

110111
<div class="box" id="coroutines">

0 commit comments

Comments
 (0)