PY-46321 Added Markdown code fence aliases for PyDocstring and Python

* PyDocstring: "pycon", "python-repl"
* Python: "py", "python3"

I've added the links to the documents describing popular references to `PyCodeFenceLanguageProvider`.

GitOrigin-RevId: 6cafb15c9655434f5d69aa47eb7472b634364377
This commit is contained in:
Andrey Vlasovskikh
2021-04-27 17:31:57 +00:00
committed by intellij-monorepo-bot
parent 42327842df
commit eaefde3c09
7 changed files with 52 additions and 0 deletions
+1
View File
@@ -789,6 +789,7 @@
<module fileurl="file://$PROJECT_DIR$/python/python-common-tests/intellij.python.commonTests.iml" filepath="$PROJECT_DIR$/python/python-common-tests/intellij.python.commonTests.iml" />
<module fileurl="file://$PROJECT_DIR$/python/openapi/intellij.python.community.iml" filepath="$PROJECT_DIR$/python/openapi/intellij.python.community.iml" />
<module fileurl="file://$PROJECT_DIR$/python/intellij.python.community.impl.iml" filepath="$PROJECT_DIR$/python/intellij.python.community.impl.iml" />
<module fileurl="file://$PROJECT_DIR$/python/python-markdown/intellij.python.markdown.iml" filepath="$PROJECT_DIR$/python/python-markdown/intellij.python.markdown.iml" />
<module fileurl="file://$PROJECT_DIR$/python/pluginCore/intellij.python.community.plugin.iml" filepath="$PROJECT_DIR$/python/pluginCore/intellij.python.community.plugin.iml" />
<module fileurl="file://$PROJECT_DIR$/python/pluginCore/impl/intellij.python.community.plugin.impl.iml" filepath="$PROJECT_DIR$/python/pluginCore/impl/intellij.python.community.plugin.impl.iml" />
<module fileurl="file://$PROJECT_DIR$/python/pluginJava/intellij.python.community.plugin.java.iml" filepath="$PROJECT_DIR$/python/pluginJava/intellij.python.community.plugin.java.iml" />
@@ -18,6 +18,7 @@ class PythonCommunityPluginModules {
"intellij.python.copyright",
"intellij.python.terminal",
"intellij.python.grazie",
"intellij.python.markdown",
"intellij.python.reStructuredText",
"intellij.python.sdk",
"intellij.python.featuresTrainer",
@@ -9,5 +9,6 @@
<orderEntry type="module" module-name="intellij.python.terminal" scope="RUNTIME" />
<orderEntry type="module" module-name="intellij.python.reStructuredText" scope="RUNTIME" />
<orderEntry type="module" module-name="intellij.python.grazie" scope="RUNTIME" />
<orderEntry type="module" module-name="intellij.python.markdown" scope="RUNTIME" />
</component>
</module>
@@ -30,6 +30,7 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
<depends optional="true" config-file="intellilang-python-support.xml">org.intellij.intelliLang</depends>
<depends optional="true" config-file="python-terminal-plugin.xml">org.jetbrains.plugins.terminal</depends>
<depends optional="true" config-file="python-grazie-plugin.xml">tanvd.grazi</depends>
<depends optional="true" config-file="python-markdown-plugin.xml">org.intellij.plugins.markdown</depends>
<depends optional="true" config-file="python-features-trainer.xml">training</depends>
<extensions defaultExtensionNs="com.intellij">
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
<orderEntry type="module" module-name="intellij.markdown" />
<orderEntry type="module" module-name="intellij.python.psi.impl" />
<orderEntry type="module" module-name="intellij.python.psi" />
</component>
</module>
@@ -0,0 +1,5 @@
<idea-plugin>
<extensions defaultExtensionNs="org.intellij.markdown">
<fenceLanguageProvider implementation="com.jetbrains.python.markdown.PyCodeFenceLanguageProvider"/>
</extensions>
</idea-plugin>
@@ -0,0 +1,27 @@
package com.jetbrains.python.markdown
import com.intellij.codeInsight.completion.CompletionParameters
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.lang.Language
import com.jetbrains.python.PythonLanguage
import com.jetbrains.python.documentation.doctest.PyDocstringLanguageDialect
import org.intellij.plugins.markdown.injection.CodeFenceLanguageProvider
/**
* Defines major Python dialects to use in Markdown code fence blocks.
*
* These dialects are listed as classes in [highlight.js][1] and in [Linguist][2] used by GitHub.
*
* [1]: https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md
* [2]: https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
*/
class PyCodeFenceLanguageProvider : CodeFenceLanguageProvider {
override fun getLanguageByInfoString(infoString: String): Language? =
when (infoString.toLowerCase()) {
"pycon", "python-repl" -> PyDocstringLanguageDialect.getInstance()
"py", "python3" -> PythonLanguage.INSTANCE
else -> null
}
override fun getCompletionVariantsForInfoString(parameters: CompletionParameters): List<LookupElement> = emptyList()
}