假设我正在查看包含内容的 Markdown 文件
```.IPYNB
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "powershell"
}
},
"outputs": [],
"source": [
"Invoke-WebRequest -URI 'https://dub.sh/zza' | ConvertFrom-JSON | Select-Object -ExpandProperty bio"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
```
这包含 3 种不同类型的代码:
```.IPYNB
```
显然是Markdown;.JSON
是 Jupyter Notebook 内容(因此是 .IPYNB
);和.IPYNB
文件的内容是包含PowerShell Core(因此是.PS1
)代码的Markdown。这是一个复杂的示例,但它演示了 VSCode 需要能够智能解析这些格式以提供语法突出显示。是否可以通过扩展或首选项启用此功能?
我问这个问题是因为 GitHub 实际上已经在一定程度上做到了这一点。例如,https://github.com/microsoft/vscode-discussions/discussions/937#discussion-5874181显示:
(尽管仅在渲染时)。
解决方案是不在语言名称之前使用文件扩展名分隔符。因此,正确的格式是
```IPYNB
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "powershell"
}
},
"outputs": [],
"source": [
"Invoke-WebRequest -URI 'https://dub.sh/zza' | ConvertFrom-JSON | Select-Object -ExpandProperty bio"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
```