自定义高亮样式

高亮Demo 预览喜欢的高亮样式,比如经典的 Monokai

然后到 GItHub 复制对应名字的CSS源码

粘贴到VS Code进行一些修改将 .hljs 替换为 .cnblogs-markdown .hljs

如果不想代码换行,还可以添加样式

1
2
3
4
5
pre {
  /*控制代码不换行*/
  white-space: pre;
  word-wrap: normal;
}

将修改后的CSS代码复制到 我的博客-->管理-->设置界面的页面定制 CSS 代码

点击保存,可以测试高亮样式是否生效,如果没有生效,可以给 CSS 代码添加 !important 提升优先级。

分享我使用的高亮样式

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Monokai style - ported by Luigi Maselli - http://grigio.org
*/
pre {
  /*控制代码不换行*/
  white-space: pre;
  word-wrap: normal;
}

.cnblogs-markdown .hljs {
  display: block;
  overflow-x: auto;
  padding: 0.5em;
  background: #272822 !important;
  color: #ddd;
}

.hljs-tag,
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-strong,
.hljs-name {
  color: #f92672;
}

.hljs-code {
  color: #66d9ef;
}

.hljs-class .hljs-title {
  color: white;
}

.hljs-attribute,
.hljs-symbol,
.hljs-regexp,
.hljs-link {
  color: #bf79db;
}

.hljs-string,
.hljs-bullet,
.hljs-subst,
.hljs-title,
.hljs-section,
.hljs-emphasis,
.hljs-type,
.hljs-built_in,
.hljs-builtin-name,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-addition,
.hljs-variable,
.hljs-template-tag,
.hljs-template-variable {
  color: #a6e22e;
}

.hljs-comment,
.hljs-quote,
.hljs-deletion,
.hljs-meta {
  color: #75715e;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-doctag,
.hljs-title,
.hljs-section,
.hljs-type,
.hljs-selector-id {
  font-weight: bold;
}