From 4db76f6276dcf491a7f7ed06b5526abf78ba538c Mon Sep 17 00:00:00 2001 From: "andrei.kislitsyn" Date: Wed, 4 Jun 2025 23:44:05 +0400 Subject: [PATCH 1/2] fix escaping in iframes --- .../explainer/PluginCallbackProxy.kt | 31 ++++++++----------- docs/README.md | 2 -- ...amples.api.Access.columnSelectorsMisc.html | 8 ++--- ...s.api.Access.columnSelectorsModifySet.html | 2 +- ...ples.api.Access.columnSelectorsUsages.html | 4 +-- ...aframe.samples.api.Analyze.columnsFor.html | 2 +- ....samples.api.Analyze.countAggregation.html | 2 +- ...ame.samples.api.DataRowApi.conditions.html | 2 +- ...aframe.samples.api.Join.joinWithMatch.html | 2 +- ....dataframe.samples.api.Modify.convert.html | 2 +- ...ataframe.samples.api.Modify.convertTo.html | 4 +-- ...ataframe.samples.api.Modify.fillNulls.html | 4 +-- ...aframe.samples.api.Modify.gatherNames.html | 2 +- ...x.dataframe.samples.api.Modify.update.html | 2 +- .../DataSchema-Data-Classes-Generation.md | 4 +-- tests/build.gradle.kts | 2 +- 16 files changed, 34 insertions(+), 41 deletions(-) diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt index dd74e411fa..226635678f 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt @@ -315,26 +315,21 @@ private fun convertToDescription(dataframeLike: Any): String = }.escapeHtmlForIFrame() internal fun String.escapeHtmlForIFrame(): String { - val str = this return buildString { - for (c in str) { - when { - c.code > 127 || c == '\'' || c == '\\' -> { - append("&#") - append(c.code) - append(';') - } - - c == '"' -> append(""") - - c == '<' -> append("&lt;") - - c == '>' -> append("&gt;") - - c == '&' -> append("&") - + for (c in this@escapeHtmlForIFrame) { + when (c) { + '<' -> append("<") + '>' -> append(">") + '&' -> append("&") + '"' -> append(""") + '\'' -> append("'") + '\\' -> append("\") else -> { - append(c) + if (c.code > 127) { + append("&#${c.code};") + } else { + append(c) + } } } } diff --git a/docs/README.md b/docs/README.md index 7fbaa78f6a..3471d1bebf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -62,5 +62,3 @@ Code samples for the documentation website reside in [core/.../test/.../samples/ and [tests/.../samples/api](../tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api) (for samples can depend on other I/O modules) and they are copied over to Markdown files in [docs/StardustDocs/topics](./StardustDocs/topics) by [Korro](https://github.com/devcrocod/korro). - - diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsMisc.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsMisc.html index 29b762e400..32e25b5553 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsMisc.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsMisc.html @@ -226,7 +226,7 @@
- df.select { colsOf&lt;String&gt;() } + df.select { colsOf<String>() }
Input DataFrame: rowsCount = 7, columnsCount = 6
@@ -242,7 +242,7 @@

- df.select { colsOf&lt;String?&gt; { it.countDistinct() &gt; 5 } } + df.select { colsOf<String?> { it.countDistinct() > 5 } }
Input DataFrame: rowsCount = 7, columnsCount = 6
@@ -438,7 +438,7 @@

- df.select { colsAtAnyDepth().colsOf&lt;String&gt;() } + df.select { colsAtAnyDepth().colsOf<String>() }
Input DataFrame: rowsCount = 7, columnsCount = 6
@@ -454,7 +454,7 @@

- df.select { allExcept { colsOf&lt;String&gt;() } } + df.select { allExcept { colsOf<String>() } }
Input DataFrame: rowsCount = 7, columnsCount = 6
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsModifySet.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsModifySet.html index 52e480ab8c..51719d24a4 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsModifySet.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsModifySet.html @@ -274,7 +274,7 @@

- df.select { (colsOf&lt;Int&gt;() and age).distinct() } + df.select { (colsOf<Int>() and age).distinct() }
Input DataFrame: rowsCount = 7, columnsCount = 5
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsUsages.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsUsages.html index 1b405ef82c..47a3e74ce2 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsUsages.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Access.columnSelectorsUsages.html @@ -194,7 +194,7 @@

- df.fillNaNs { colsAtAnyDepth().colsOf&lt;Double&gt;() }.withZero() + df.fillNaNs { colsAtAnyDepth().colsOf<Double>() }.withZero()
Input DataFrame: rowsCount = 7, columnsCount = 5
@@ -270,7 +270,7 @@

- df.gather { colsOf&lt;Number&gt;() }.into("key", "value") + df.gather { colsOf<Number>() }.into("key", "value")
Input DataFrame: rowsCount = 7, columnsCount = 5
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Analyze.columnsFor.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Analyze.columnsFor.html index d4307ef33d..e2c2e9c371 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Analyze.columnsFor.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Analyze.columnsFor.html @@ -178,7 +178,7 @@
- df.minFor { colsOf&lt;Int&gt;() } + df.minFor { colsOf<Int>() }
Input DataFrame: rowsCount = 7, columnsCount = 5
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Analyze.countAggregation.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Analyze.countAggregation.html index 8606bab038..8f74a8f1b6 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Analyze.countAggregation.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Analyze.countAggregation.html @@ -200,7 +200,7 @@

- df.pivot { city }.count { age &gt; 18 } + df.pivot { city }.count { age > 18 }
Input DataFrame: rowsCount = 7, columnsCount = 5
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.DataRowApi.conditions.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.DataRowApi.conditions.html index 6ddaed2e0a..43fa7239b7 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.DataRowApi.conditions.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.DataRowApi.conditions.html @@ -210,7 +210,7 @@

- df.update { weight }.where { index() &gt; 4 && city != "Paris" }.with { 50 } + df.update { weight }.where { index() > 4 && city != "Paris" }.with { 50 }
Input DataFrame: rowsCount = 7, columnsCount = 5
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Join.joinWithMatch.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Join.joinWithMatch.html index 0b0c689c68..7637c598c4 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Join.joinWithMatch.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Join.joinWithMatch.html @@ -178,7 +178,7 @@
- other.into("fullName").cast&lt;Right&gt;() + other.into("fullName").cast<Right>()
Input DataFrame: rowsCount = 7, columnsCount = 3
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.convert.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.convert.html index 5038a6108b..4e7091b319 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.convert.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.convert.html @@ -198,7 +198,7 @@

- df.convert { colsAtAnyDepth().colsOf&lt;String&gt;() }.with { it.toCharArray().toList() } + df.convert { colsAtAnyDepth().colsOf<String>() }.with { it.toCharArray().toList() }
Input DataFrame: rowsCount = 7, columnsCount = 5
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.convertTo.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.convertTo.html index efbbbc02a4..c915e7f07d 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.convertTo.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.convertTo.html @@ -178,7 +178,7 @@
- df.convert { age }.to&lt;Double&gt;() + df.convert { age }.to<Double>()
Input DataFrame: rowsCount = 7, columnsCount = 5
@@ -198,7 +198,7 @@

- df.convert { colsOf&lt;Number&gt;() }.to&lt;String&gt;() + df.convert { colsOf<Number>() }.to<String>()
Input DataFrame: rowsCount = 7, columnsCount = 5
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.fillNulls.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.fillNulls.html index 09e320d860..458a2e13c1 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.fillNulls.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.fillNulls.html @@ -178,7 +178,7 @@
- df.fillNulls { colsOf&lt;Int?&gt;() }.with { -1 } + df.fillNulls { colsOf<Int?>() }.with { -1 }
Input DataFrame: rowsCount = 7, columnsCount = 5
@@ -200,7 +200,7 @@

- df.update { colsOf&lt;Int?&gt;() }.where { it == null }.with { -1 } + df.update { colsOf<Int?>() }.where { it == null }.with { -1 }
Input DataFrame: rowsCount = 7, columnsCount = 5
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.gatherNames.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.gatherNames.html index 7ddf1b7f20..b1fdf69db2 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.gatherNames.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.gatherNames.html @@ -200,7 +200,7 @@

- pivoted.gather { "London".."Tokyo" }.cast&lt;Int&gt;().where { it &gt; 0 }.keysInto("city") + pivoted.gather { "London".."Tokyo" }.cast<Int>().where { it > 0 }.keysInto("city")
Input DataFrame: rowsCount = 6, columnsCount = 9
diff --git a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.update.html b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.update.html index 711a792446..0bb71306cc 100644 --- a/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.update.html +++ b/docs/StardustDocs/resources/snippets/org.jetbrains.kotlinx.dataframe.samples.api.Modify.update.html @@ -200,7 +200,7 @@

- df.update { colsAtAnyDepth().colsOf&lt;String&gt;() }.with { it.uppercase() } + df.update { colsAtAnyDepth().colsOf<String>() }.with { it.uppercase() }
Input DataFrame: rowsCount = 7, columnsCount = 5
diff --git a/docs/StardustDocs/topics/DataSchema-Data-Classes-Generation.md b/docs/StardustDocs/topics/DataSchema-Data-Classes-Generation.md index f369b5fa9d..d5faa6c626 100644 --- a/docs/StardustDocs/topics/DataSchema-Data-Classes-Generation.md +++ b/docs/StardustDocs/topics/DataSchema-Data-Classes-Generation.md @@ -164,8 +164,6 @@ val customers: List = df.cast().toList() - - ## generateCode ```kotlin @@ -202,6 +200,8 @@ the generated Kotlin code of `@DataSchema` interfaces and/or extension propertie ### Examples {id="generateCode-examples"} + + ```kotlin df.generateCode("Customer") ``` diff --git a/tests/build.gradle.kts b/tests/build.gradle.kts index 8018e92240..7229065b7b 100644 --- a/tests/build.gradle.kts +++ b/tests/build.gradle.kts @@ -61,7 +61,7 @@ kotlin.sourceSets { korro { docs = fileTree(rootProject.rootDir) { // todo topics/*.md as a part of #898 - include("docs/StardustDocs/topics/Utilities-Generation.md") + include("docs/StardustDocs/topics/DataSchema-Data-Classes-Generation.md") include("docs/StardustDocs/topics/read.md") include("docs/StardustDocs/topics/write.md") include("docs/StardustDocs/topics/rename.md") From 56140f136883bac54ab1617d34b6bc10782bf718 Mon Sep 17 00:00:00 2001 From: "andrei.kislitsyn" Date: Thu, 5 Jun 2025 14:34:44 +0400 Subject: [PATCH 2/2] ktlint format --- .../dataframe/explainer/PluginCallbackProxy.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt index 226635678f..17bb2f618c 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt @@ -314,16 +314,22 @@ private fun convertToDescription(dataframeLike: Any): String = else -> throw IllegalArgumentException("Unsupported type: ${dataframeLike::class}") }.escapeHtmlForIFrame() -internal fun String.escapeHtmlForIFrame(): String { - return buildString { +internal fun String.escapeHtmlForIFrame(): String = + buildString { for (c in this@escapeHtmlForIFrame) { when (c) { '<' -> append("<") + '>' -> append(">") + '&' -> append("&") + '"' -> append(""") + '\'' -> append("'") + '\\' -> append("\") + else -> { if (c.code > 127) { append("&#${c.code};") @@ -334,4 +340,3 @@ internal fun String.escapeHtmlForIFrame(): String { } } } -}