Skip to content

Commit 5c18bfd

Browse files
authored
Merge pull request #968 from Kotlin/html-preview-improvements
Add kdoc about "Open in browser" from IDEA that helps to streamline working with HTML rendering
2 parents cdbb23f + a01097f commit 5c18bfd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

core/api/core.api

+1
Original file line numberDiff line numberDiff line change
@@ -10403,6 +10403,7 @@ public final class org/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData {
1040310403
public fun toString ()Ljava/lang/String;
1040410404
public final fun withTableDefinitions ()Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData;
1040510405
public final fun writeHTML (Ljava/io/File;)V
10406+
public final fun writeHTML (Ljava/lang/String;)V
1040610407
public final fun writeHTML (Ljava/nio/file/Path;)V
1040710408
}
1040810409

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,11 @@ internal fun DataFrameHtmlData.print() = println(this)
518518
/**
519519
* By default, cell content is formatted as text
520520
* Use [RenderedContent.media] or [IMG], [IFRAME] if you need custom HTML inside a cell.
521-
* @return DataFrameHtmlData with table script and css definitions. Can be saved as an *.html file and displayed in the browser
521+
*
522+
* The [DataFrameHtmlData] be saved as an *.html file and displayed in the browser.
523+
* If you save it as a file and find it in the project tree,
524+
* the ["Open in browser"](https://www.jetbrains.com/help/idea/editing-html-files.html#ws_html_preview_output_procedure) feature of IntelliJ IDEA will automatically reload the file content when it's updated
525+
* @return DataFrameHtmlData with table script and css definitions
522526
*/
523527
public fun <T> DataFrame<T>.toStandaloneHTML(
524528
configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT,
@@ -620,10 +624,18 @@ public data class DataFrameHtmlData(
620624
destination.writeText(toString())
621625
}
622626

627+
public fun writeHTML(destination: String) {
628+
File(destination).writeText(toString())
629+
}
630+
623631
public fun writeHTML(destination: Path) {
624632
destination.writeText(toString())
625633
}
626634

635+
/**
636+
* Opens a new tab in your default browser.
637+
* Consider [writeHTML] with the [HTML file auto-reload](https://www.jetbrains.com/help/idea/editing-html-files.html#ws_html_preview_output_procedure) feature of IntelliJ IDEA if you want to experiment with the output and run program multiple times
638+
*/
627639
public fun openInBrowser() {
628640
val file = File.createTempFile("df_rendering", ".html")
629641
writeHTML(file)

0 commit comments

Comments
 (0)