Editor 如何在visual studio代码标记预览中使用联机style.css?
我在github中找到了一个降价css,我想用它预览我的vscode的md文件。 css文件url为: vscode settings.json: 但什么也没发生。Editor 如何在visual studio代码标记预览中使用联机style.css?,editor,visual-studio-code,Editor,Visual Studio Code,我在github中找到了一个降价css,我想用它预览我的vscode的md文件。 css文件url为: vscode settings.json: 但什么也没发生。 我应该怎么做?如果您想使用本地.css文件,例如d:\vscode markdown.css,那么您的配置应该是 "markdown.styles": [ "file:///D:/vscode-markdown.css" ] 的css文件不适合编辑器 该文档已经编写了css预览的格式 body { font-fam
我应该怎么做?如果您想使用本地.css文件,例如
d:\vscode markdown.css
,那么您的配置应该是
"markdown.styles": [
"file:///D:/vscode-markdown.css"
]
的css文件不适合编辑器
该文档已经编写了css预览的格式
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
h1 {
color: cornflowerblue;
}
- 工作场所设置:将
放入样式.css
中,配置工作区文件夹
也会起作用“markdown.styles”:[“style.css”]
- 全局设置:将绝对本地路径与
协议一起使用文件://
- 这里是我为一个个人项目做的一个小设置——它与您最初想要的非常接近
~/.vscode/settings.json
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true
},
"files.trimTrailingWhitespace": true,
"search.exclude": {
"**/node_modules": true
},
"markdown.styles": [
"tools/editors/vscode/settings/markdown.styles.css"
]
}
~/package.json
{
"name": "seed",
"main": "index.js",
...
"scripts": {
"postinstall": "node tools/editors/vscode/settings/markdown.styles.js",
},
...
"devDependencies": {
"generate-github-markdown-css": "^1.2.0",
}
}
~/tools/editors/vscode/settings/markdown.styles.js
'use strict'
const fs = require('fs')
const githubMarkdownCss = require('generate-github-markdown-css')
/**
* Use the stylesheet from github's markdown over the vscode defaults.
*/
githubMarkdownCss((err, css) => {
css = `body {\n background-color: #fff;\n}\n\n${css.replace(/.markdown-body/g, 'body')}`
fs.writeFileSync('tools/editors/vscode/settings/markdown.styles.css', css, 'utf8')
})
//NOTE: the CSS var is set with es6 string interpolation. (node 4.x and up)
// the background-color is set here because GitHub inherit's it from another stylesheet -- so we need to set it.
希望这对某人有所帮助。(另外,为疯狂的文件路径感到抱歉) 干杯 vscode似乎是从标记文件本身的位置开始的,因此,通用绝对路径规范似乎只能从文件系统的根而不是项目的根开始 更新 我刚刚注意到vscode正在向MS的团队发送应用程序洞察,这是基于无法解析文件。下面所示的方法是有效的,但是如果它产生了错误,那么它可能会有点剧烈。如果需要这样做,至少应该禁用insights,或者干脆将css复制到与标记相同的文件夹中 现在,我只需将
markdown.css
保存在根文件夹中,并使用允许将markdown放置到项目中各个子文件夹中的路径使配置饱和。当然,这里只需要一个实际的样式源,只需要给vscode更多的地方来查找它
项目文件夹
settings.json
markdown.css
使用Github/Gist中的原始URL,并将其与一起使用 下面是我的VSCode设置中的一个示例,它可以正常工作。您应该可以在白色背景和黑色文本的背景下看到Fira Sans和Fira Mono字体
// settings.json from VSCode
{
...
"markdown.styles": ["https://rawgit.com/thewazir/50486310d50fb2d6da2c8ab91d26756a/raw/1760755deb7bff05fadcaf6927c4950d256e6838/visualStudioCodeMarkdownStyles.css"]
}
目前的答案已经过时了。要在预览中使用github样式,请尝试
要将任何样式表加载到预览中,https链接通常在
markdown.styles
中工作,但github在该资源上,因此我们无法嵌入到markdown预览中
作为解决方法,您可以:
- 对github内容使用https镜像
- 将样式表下载到您的工作区,并使用以包含它
重要信息:降价预览只能从当前工作区内加载样式表"markdown.styles": ["github-markdown.css"]
git submodule Add”https://github.com/SepCode/vscode-markdown-style.git
”。现在我们可以使用URL“”设置markdown.styles
步骤:
git克隆https://github.com/SepCode/SepCode.github.io.git
”cd SepCode.github.io
git子模块添加https://github.com/SepCode/vscode-markdown-style.git
git提交-am“添加了vscode标记样式模块”
git推送
{
“markdown.styles”:[“https://sepcode.github.io/vscode-markdown-style/preview/github.css"]
}
我添加了一种方法,可以让sindresorhus的软件包使用一点节点黑客攻击,如果你不使用我们的节点,我可以提供更详细的描述——另外,我发现这个URL使用GitHub内容更方便——这在现代版本的VS代码中不起作用。只能从工作区内部加载本地样式文件
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": false,
"markdown.styles": [
"./markdown.css",
"../markdown.css",
"../../markdown.css",
"../../../markdown.css"
]
}
body {
font-family: cordova, Verdana, Geneva, Tahoma, sans-serif;
font-size: 14px;
line-height: 1.6;
background-color: white;
padding: 20px;
color: #333;
}
body, body * {
background-color: white !important;
color: black;
}
pre {
margin: 0 !important;
padding: 0 !important;
box-sizing: border-box;
margin-bottom: -1.25em !important;
}
pre div {
padding: 10px;
background-color: #eee !important;
border-radius: 2px;
overflow: auto;
}
pre code * {
color: black !important;
background-color: #eee !important;
}
// settings.json from VSCode
{
...
"markdown.styles": ["https://rawgit.com/thewazir/50486310d50fb2d6da2c8ab91d26756a/raw/1760755deb7bff05fadcaf6927c4950d256e6838/visualStudioCodeMarkdownStyles.css"]
}
"markdown.styles": ["github-markdown.css"]