-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Markdown Rendering in the What's New Panel (#432)
This is a PR for markdown file (.md) rendering and formatting for the "What's New at Slack!" side panel in the Skate plugin. This change went through a few iterations because I was having trouble using intelliJ's markdown plugin in Skate, so I had done custom CSS formatting before. However, now I was able to use MarkdownJCEFHtmlPanel to properly format the md files. Here is what it looks like as it depends on the formatting for the markdown plugin with intelliJ: <img width="665" alt="Screenshot 2023-07-06 at 5 31 07 PM" src="https://github.com/slackhq/slack-gradle-plugin/assets/67719108/d8198ce1-224d-4e31-8f47-f6c4df60776d"> <img width="466" alt="Screenshot 2023-07-06 at 6 02 59 PM" src="https://github.com/slackhq/slack-gradle-plugin/assets/67719108/1d74e9dc-0985-4277-ac34-e158353abb4c"> <!-- ⬆ Put your description above this! ⬆ Please be descriptive and detailed. Please read our [Contributing Guidelines](https://github.com/tinyspeck/slack-gradle-plugin/blob/main/.github/CONTRIBUTING.md) and [Code of Conduct](https://slackhq.github.io/code-of-conduct). Don't worry about deleting this, it's not visible in the PR! --> --------- Co-authored-by: Zac Sweers <[email protected]>
- Loading branch information
Showing
6 changed files
with
118 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
skate-plugin/src/main/kotlin/com/slack/sgp/intellij/WhatsNewPanelFactory.kt
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
skate-plugin/src/main/kotlin/com/slack/sgp/intellij/ui/WhatsNewPanelFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (C) 2023 Slack Technologies, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.slack.sgp.intellij.ui | ||
|
||
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.application.runReadAction | ||
import com.intellij.openapi.project.DumbAware | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.Disposer | ||
import com.intellij.openapi.wm.ToolWindow | ||
import com.intellij.testFramework.LightVirtualFile | ||
import com.intellij.ui.content.ContentFactory | ||
import com.intellij.ui.content.ContentManagerEvent | ||
import com.intellij.ui.content.ContentManagerListener | ||
import java.awt.BorderLayout | ||
import javax.swing.JComponent | ||
import javax.swing.JPanel | ||
import org.intellij.lang.annotations.Language | ||
import org.intellij.plugins.markdown.ui.preview.html.MarkdownUtil | ||
import org.intellij.plugins.markdown.ui.preview.jcef.MarkdownJCEFHtmlPanel | ||
|
||
/** | ||
* The WhatsNewPanelFactory class takes the markdown file string from SkateService and displays it | ||
* in a tool window. It uses MarkdownJCEFHtmlPanel and has dependency on intellij markdown plugin to | ||
* properly format the markdown file and its contents | ||
*/ | ||
class WhatsNewPanelFactory : DumbAware { | ||
|
||
// Function that creates the tool window | ||
fun createToolWindowContent( | ||
toolWindow: ToolWindow, | ||
project: Project, | ||
markdownFileString: String, | ||
parentDisposable: Disposable | ||
) { | ||
|
||
val toolWindowContent = WhatsNewPanelContent(project, markdownFileString, parentDisposable) | ||
val content = | ||
ContentFactory.getInstance().createContent(toolWindowContent.contentPanel, "", false) | ||
toolWindow.contentManager.addContent(content) | ||
toolWindow.contentManager.addContentManagerListener( | ||
object : ContentManagerListener { | ||
override fun contentRemoved(event: ContentManagerEvent) { | ||
if (event.content.component == toolWindowContent.contentPanel) { | ||
Disposer.dispose(parentDisposable) | ||
toolWindow.contentManager.removeContentManagerListener(this) | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
private class WhatsNewPanelContent( | ||
project: Project, | ||
@Language("Markdown") markdownFileString: String, | ||
parentDisposable: Disposable | ||
) { | ||
|
||
// Actual panel box for What's New at Slack | ||
val contentPanel: JPanel = | ||
JPanel().apply { | ||
layout = BorderLayout(0, 20) | ||
add(createWhatsNewPanel(project, markdownFileString, parentDisposable), BorderLayout.CENTER) | ||
} | ||
|
||
// Control Panel that takes in the current project, markdown string, and a Disposable. | ||
private fun createWhatsNewPanel( | ||
project: Project, | ||
@Language("Markdown") markdownFileString: String, | ||
parentDisposable: Disposable | ||
): JComponent { | ||
// to take in the parsed Changelog: | ||
// val parsedChangelog = ChangelogParser.readFile(markdownFileString) | ||
// then, pass in parsedChangelog instead of markdownFileString | ||
|
||
val file = LightVirtualFile("changelog.md", markdownFileString) | ||
|
||
val panel = MarkdownJCEFHtmlPanel(project, file) | ||
Disposer.register(parentDisposable, panel) | ||
val html = runReadAction { | ||
MarkdownUtil.generateMarkdownHtml(file, markdownFileString, project) | ||
} | ||
|
||
panel.setHtml(html, 0) | ||
return panel.component | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters