Skip to content

Commit

Permalink
Add kdoc about "Open in browser" from IDEA that helps to streamline w…
Browse files Browse the repository at this point in the history
…orking with HTML rendering
  • Loading branch information
koperagen committed Nov 25, 2024
1 parent 8d59c97 commit 449eb96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -10347,6 +10347,7 @@ public final class org/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData {
public fun toString ()Ljava/lang/String;
public final fun withTableDefinitions ()Lorg/jetbrains/kotlinx/dataframe/io/DataFrameHtmlData;
public final fun writeHTML (Ljava/io/File;)V
public final fun writeHTML (Ljava/lang/String;)V
public final fun writeHTML (Ljava/nio/file/Path;)V
}

Expand Down
14 changes: 13 additions & 1 deletion core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ internal fun DataFrameHtmlData.print() = println(this)
/**
* By default, cell content is formatted as text
* Use [RenderedContent.media] or [IMG], [IFRAME] if you need custom HTML inside a cell.
* @return DataFrameHtmlData with table script and css definitions. Can be saved as an *.html file and displayed in the browser
*
* [DataFrameHtmlData] be saved as an *.html file and displayed in the browser.
* If you save it as a file and find it in the project tree,
* ["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 file content when it's updated
* @return DataFrameHtmlData with table script and css definitions
*/
public fun <T> DataFrame<T>.toStandaloneHTML(
configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT,
Expand Down Expand Up @@ -620,10 +624,18 @@ public data class DataFrameHtmlData(
destination.writeText(toString())
}

public fun writeHTML(destination: String) {
File(destination).writeText(toString())
}

public fun writeHTML(destination: Path) {
destination.writeText(toString())
}

/**
* Opens a new tab in your default browser.
* Consider [writeHTML] with [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
*/
public fun openInBrowser() {
val file = File.createTempFile("df_rendering", ".html")
writeHTML(file)
Expand Down

0 comments on commit 449eb96

Please sign in to comment.