简体   繁体   English

使用GitHub与VSCode实时预览降价

[英]Live preview of markdown using GitHub with VSCode

I'm trying to set the CSS file that I'd like Visual Studio Code to use when using a preview rendering of the markdown file I'm working on so that the style mirrors the GitHub style CSS... but so far unable to do it. 我正在尝试设置我要使用的Visual Studio Code在使用正在处理的markdown文件的预览呈现时使用的CSS文件,以使该样式反映GitHub样式CSS。但是到目前为止,做吧。

I get that VSCode uses the same CSS that matches what VSCode uses, but I'd like it to instead use GitHub's CSS. 我得到VSCode使用与VSCode使用的CSS相同的CSS,但我希望它改用GitHub的CSS。 I've tried saving the CSS file from GitHub onto my system and then referencing the full path to that CSS within the settings.json file using the instructions here: https://code.visualstudio.com/Docs/languages/markdown#_using-your-own-css 我尝试将CS​​S文件从GitHub保存到我的系统上,然后按照以下说明在settings.json文件中引用该CSS的完整路径: https : //code.visualstudio.com/Docs/languages/markdown#_using -您-拥有- CSS

But it isn't taking effect it seems... is this actually working in VSCode? 但这似乎没有生效……这实际上在VSCode中有效吗? I'm using the latest version 0.7.0. 我正在使用最新的版本0.7.0。

updated Here's how I have it setup. 已更新这是我的设置方法。 Within my workspace I have a file .settings/settings.json that contains: 在我的工作区中,我有一个.settings/settings.json文件,其中包含:

{
  "markdown.styles": ["github-markdown.css"]
}

Then I have the CSS file located in .settings/github-markdown.css . 然后,我在.settings/github-markdown.css找到了CSS文件。 I've tried using the contents of the following two CSS files... 我尝试使用以下两个CSS文件的内容...

...but neither is having any impact. ...但是都没有任何影响。 I've also tried a fully qualified path tot he CSS file and relative ( ./github-markdown.css ). 我还尝试了CSS文件和相对( ./github-markdown.css )的完全限定路径。 Between each change, I've also restarted VSCode to see if that had an impact. 在每次更改之间,我还重新启动了VSCode,以查看是否有影响。

Paths to markdown styles will be resolved relative to the root of your workspace. 降价样式的路径将相对于工作空间的根进行解析。 I can get markdown styling to work with the following steps: 我可以通过以下步骤使用markdown样式:

  • add an entry to the workspace settings "markdown.styles": [ "styles.css" ] 在工作区设置"markdown.styles": [ "styles.css" ]添加一个条目"markdown.styles": [ "styles.css" ]
  • create a top level styles.css file and add a simple rule body { color: red; } 创建一个顶级styles.css文件,并添加一个简单的规则body { color: red; } body { color: red; }
  • create a markdown file or open an existing one and preview it 创建markdown文件或打开现有文件并预览

The text of the markdown should appear in red. 降价文字应显示为红色。

If you are using CSS classes with a specific prefix, you have to make sure that those classes are in your markdown code. 如果您使用带有特定前缀的CSS类,则必须确保这些类在markdown代码中。 VSCode is not adding CSS classes by itself. VSCode本身并没有添加CSS类。

VSCode has it's own CSS for markdown rendering. VSCode拥有自己的CSS,用于markdown渲染。

C:\\Program Files (x86)\\Microsoft VS Code\\resources\\app\\extensions\\markdown\\media\\markdown.css

This is the main reason why custom CSS does not apply. 这是自定义CSS不适用的主要原因。

I've override some attributes and it works well now. 我已经覆盖了一些属性,并且现在效果很好。

I've uploaded codes to my github repository . 我已经将代码上传到我的github仓库中

I hope this helps you. 我希望这可以帮助你。

If you want to use that file " https://github.com/SepCode/vscode-markdown-style/blob/master/preview/github.css ", we know that " https://raw.githubusercontent.com/SepCode/vscode-markdown-style/master/preview/github.css ", the URL is not working. 如果要使用该文件“ https://github.com/SepCode/vscode-markdown-style/blob/master/preview/github.css ”,我们知道“ https://raw.githubusercontent.com/SepCode /vscode-markdown-style/master/preview/github.css “,则该URL无法正常工作。

I have a good idea, we can use Github Pages. 我有一个好主意,我们可以使用Github Pages。

Add a submodule in your repository, like this " git submodule add https://github.com/SepCode/vscode-markdown-style.git ". 在您的存储库中添加一个子模块,例如“ git submodule add https://github.com/SepCode/vscode-markdown-style.git ”。 And now we can use the URL " https://sepcode.github.io/vscode-markdown-style/preview/github.css " set markdown.styles. 现在我们可以使用URL“ https://sepcode.github.io/vscode-markdown-style/preview/github.css ”设置markdown.styles。

Step: 步:

  • clone your GitHub pages " git clone https://github.com/SepCode/SepCode.github.io.git " 克隆您的GitHub页面“ git clone https://github.com/SepCode/SepCode.github.io.git
  • cd SepCode.github.io
  • git submodule add https://github.com/SepCode/vscode-markdown-style.git
  • git commit -am 'added vscode-markdown-style module'
  • git push
  • setting vscode setting.json 设置vscode setting.json
     { "markdown.styles":["https://sepcode.github.io/vscode-markdown-style/preview/github.css"] } 

the vscode-markdown-style repository is just an example, we should use ourself's CSS file. vscode-markdown风格的存储库只是一个例子,我们应该使用自己的CSS文件。 This way is more convenient and controllable. 这种方式更加方便和可控。

https://github.com/microsoft/vscode/issues/76384#issuecomment-507101841 https://github.com/microsoft/vscode/issues/76384#issuecomment-507101841

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM