Skip to content

Commit

Permalink
Merge pull request #968 from Kotlin/html-preview-improvements
Browse files Browse the repository at this point in the history
Add kdoc about "Open in browser" from IDEA that helps to streamline working with HTML rendering
  • Loading branch information
koperagen authored Dec 12, 2024
2 parents cdbb23f + a01097f commit 5c18bfd
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 @@ -10403,6 +10403,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
*
* The [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,
* 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
* @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 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
*/
public fun openInBrowser() {
val file = File.createTempFile("df_rendering", ".html")
writeHTML(file)
Expand Down

0 comments on commit 5c18bfd

Please sign in to comment.