Skip to content

Commit dcec695

Browse files
committed
Add AnyFrame.toHTML overload for browsers
1 parent 156a607 commit dcec695

File tree

2 files changed

+12
-2
lines changed
  • core/src

2 files changed

+12
-2
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,18 @@ internal fun initHtml(
181181
body = "",
182182
)
183183

184+
@Deprecated("Clarify difference with .toHTML()", ReplaceWith("this.toStandaloneHTML()", "org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML"))
184185
public fun <T> DataFrame<T>.html(): String = toHTML(extraHtml = initHtml()).toString()
185186

187+
/**
188+
* @return HTML String that be saved as an *.html file and displayed in the browser
189+
*/
190+
public fun <T> DataFrame<T>.toStandaloneHTML(
191+
configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT,
192+
cellRenderer: CellRenderer = org.jetbrains.kotlinx.dataframe.jupyter.DefaultCellRenderer,
193+
getFooter: (DataFrame<T>) -> String = { "DataFrame [${it.size}]" },
194+
): String = toHTML(configuration, extraHtml = initHtml(), cellRenderer, getFooter).toString()
195+
186196
public fun <T> DataFrame<T>.toHTML(
187197
configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT,
188198
extraHtml: HtmlData? = null,

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/HtmlRenderingTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
77
import org.jetbrains.kotlinx.dataframe.api.group
88
import org.jetbrains.kotlinx.dataframe.api.into
99
import org.jetbrains.kotlinx.dataframe.api.parse
10-
import org.jetbrains.kotlinx.dataframe.io.html
1110
import org.jetbrains.kotlinx.dataframe.io.initHtml
1211
import org.jetbrains.kotlinx.dataframe.io.toHTML
12+
import org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML
1313
import org.jetbrains.kotlinx.jupyter.findNthSubstring
1414
import org.junit.Ignore
1515
import org.junit.Test
@@ -36,7 +36,7 @@ class HtmlRenderingTests : BaseTest() {
3636
fun `render url`() {
3737
val address = "http://www.google.com"
3838
val df = dataFrameOf("url")(address).parse()
39-
val html = df.html()
39+
val html = df.toStandaloneHTML()
4040
html shouldContain "href"
4141
html.findNthSubstring(address, 2) shouldNotBe -1
4242
}

0 commit comments

Comments
 (0)