mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 14:01:44 +07:00
PY-72961 Packaging: show numpy info and other md descriptions
GitOrigin-RevId: 8b25964eeae581e09dc928a864b9c4d7693f7d48
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7ded014d91
commit
05c9e88933
18
python/pluginResources/packaging/md.template.html
Normal file
18
python/pluginResources/packaging/md.template.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Marked in the browser</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content"></div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<script>
|
||||
|
||||
let mdText = `
|
||||
{MD_TEXT}
|
||||
`
|
||||
document.getElementById('content').innerHTML = marked.parse(mdText)
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -20,9 +20,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.ModuleRootEvent
|
||||
import com.intellij.openapi.roots.ModuleRootListener
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.platform.ide.progress.withBackgroundProgress
|
||||
import com.intellij.platform.util.progress.reportRawProgress
|
||||
import com.jetbrains.python.PyBundle.message
|
||||
@@ -48,7 +46,6 @@ import com.jetbrains.python.sdk.pythonSdk
|
||||
import com.jetbrains.python.sdk.sdkFlavor
|
||||
import com.jetbrains.python.statistics.modules
|
||||
import kotlinx.coroutines.*
|
||||
import org.intellij.plugins.markdown.ui.preview.html.MarkdownUtil
|
||||
import org.jetbrains.annotations.Nls
|
||||
|
||||
@Service(Service.Level.PROJECT)
|
||||
@@ -252,7 +249,7 @@ class PyPackagingToolWindowService(val project: Project, val serviceScope: Corou
|
||||
suspend fun convertToHTML(contentType: String?, description: String): String {
|
||||
return withContext(Dispatchers.IO) {
|
||||
when (contentType?.split(';')?.firstOrNull()?.trim()) {
|
||||
"text/markdown" -> markdownToHtml(description, ProjectRootManager.getInstance(project).contentRoots.first(), project)
|
||||
"text/markdown" -> markdownToHtml(description)
|
||||
"text/x-rst", "" -> rstToHtml(description, currentSdk!!)
|
||||
else -> description
|
||||
}
|
||||
@@ -306,8 +303,12 @@ class PyPackagingToolWindowService(val project: Project, val serviceScope: Corou
|
||||
}
|
||||
}
|
||||
|
||||
private fun markdownToHtml(text: String, homeDir: VirtualFile, project: Project): String {
|
||||
return wrapHtml(MarkdownUtil.generateMarkdownHtml(homeDir, text, project))
|
||||
private fun markdownToHtml(text: String): String {
|
||||
val mdHtml = PyPIPackageRanking::class.java.getResource("/packaging/md.template.html")?.readText() ?: error("Cannot get md template")
|
||||
val quotedText = text.replace("`", "\\`")
|
||||
|
||||
val prepared = mdHtml.replace("{MD_TEXT}", "\n" + quotedText)
|
||||
return prepared
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
|
||||
Reference in New Issue
Block a user