简体   繁体   English

在以下编辑器中的至少一个中,是否可以在 Markdown 语法中使用彩色标题:Sublime Text 3、Vim 或 Visual Studio Code?

[英]Is it possible to have multicolored headings in markdown syntax in at least one of these editors: Sublime Text 3, Vim or Visual Studio Code?

Essentially I would like for my headings to look like this:基本上我希望我的标题看起来像这样:

医学博士

How could I accomplish this in markdown syntax?我怎么能用降价语法完成这个? I prefer sublime text but would be happy if I can make this happen in Sublime Text 3, Vim or Visual Studio Code.我更喜欢 sublime text,但如果我能在 Sublime Text 3、Vim 或 Visual Studio Code 中实现这一点,我会很高兴。 Lastly, if getting the subheadings to produce multicolors is difficult, then, how could I change the hashtag color of all headings to the same color.最后,如果让副标题产生多色很困难,那么我如何将所有标题的主题标签颜色更改为相同的颜色。 For example, all of my headings would have green hashtags but the heading font color would be #FFFFFF .例如,我的所有标题都带有绿色主题标签,但标题字体颜色为#FFFFFF

Thank you for your help.感谢您的帮助。

In Vim, you can override your color scheme by adding the following in a new file named ~/.vim/after/syntax/markdown.vim :在 Vim 中,您可以通过在名为~/.vim/after/syntax/markdown.vim的新文件中添加以下内容来覆盖您的配色方案:

syn match    customHeader1     "^# "
syn match    customHeader2     "^## "
syn match    customHeader3     "^### "
syn match    customHeader4     "^#### "
syn match    customHeader5     "^##### "

highlight customHeader1 ctermfg=34
highlight customHeader2 ctermfg=32
highlight customHeader3 ctermfg=127
highlight customHeader4 ctermfg=45
highlight customHeader5 ctermfg=220

It creates 5 syntax groups ( customHeader1 to customHeader4 ) matching the given regexes.它创建了 5 个匹配给定正则表达式的语法组( customHeader1customHeader4 )。 Then it defines the colors for those groups.然后定义这些组的颜色。

34, 32, 127, 45, 220 are the colors, They should match your example. 34、32、127、45、220 是颜色,它们应该与您的示例相匹配。 It renders as follow:它呈现如下:

结果

Also, you need to have:此外,您还需要:

syntax on

in your .vimrc在你的.vimrc

With Sublime Text 3, you can also define one specific color for 3 header levels.使用 Sublime Text 3,您还可以为 3 个标题级别定义一种特定颜色。

If you have already a theme with specific markdown colors, edit your .tmTheme file and search for如果您已经有一个带有特定 Markdown 颜色的主题,请编辑您的 .tmTheme 文件并搜索

<string>markup.heading, markup.heading punctuation</string>

This is the default heading color that is used for all heading levels.这是用于所有标题级别的默认标题颜色。

If you duplicate the parent <dict> block for this entry, you can put a specific color for 1st heading level (# in markdown) by changing <string> like this :如果您复制此条目的父 <dict> 块,您可以通过像这样更改 <string> 为第一个标题级别(标记中的#)添加特定颜色:

<string>markup.heading.1, markup.heading.1 punctuation</string>

if you duplicate one more you can change the 2nd level color (## in markdown) :如果您再复制一个,您可以更改第二级颜色(降价中的##):

<string>markup.heading.2, markup.heading.2 punctuation</string>

Other levels ### etc. are not defined so you cannot add specific colors for them (but it is in fact still possible if you modify your Markdown.sublime-syntax file and extends it to other heading levels, with the same type of patterns code used for level 1 and level 2 headings)其他级别 ### 等未定义,因此您无法为它们添加特定颜色(但实际上,如果您修改Markdown.sublime-syntax文件并将其扩展到其他标题级别,使用相同类型的模式,它仍然是可能的用于 1 级和 2 级标题的代码)

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

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