跳至正文

修改WordPress代码高亮插件SyntaxHighlighter的字体大小

  • 干货

SyntaxHighlighter Evolved 是 WordPress 码农必备的一款插件,功能是实现代码高亮显示。这款插件应该是 WordPress 使用量最广泛的一款代码高亮插件了。但该插件的设计人员不知道是怎么想的,用的那么大的字体来显示代码,让原本就复杂的代码看起来眼花缭乱的。特别是当一行代码很长时,更是显得很乱。

要修改 SyntaxHighlighter Evolved 插件的字体,其实很简单,编辑 wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shCore.css,修改如下几个地方:

.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
  -moz-border-radius: 0 0 0 0 !important;
  -webkit-border-radius: 0 0 0 0 !important;
  background: none !important;
  border: 0 !important;
  bottom: auto !important;
  float: none !important;
  height: auto !important;
  left: auto !important;
  line-height: 1.5em !important;   /* 行间距加到1.5em刚刚好 */
  margin: 0 !important;
  outline: 0 !important;
  overflow: visible !important;
  padding: 0 !important;
  position: static !important;
  right: auto !important;
  text-align: left !important;
  top: auto !important;
  vertical-align: baseline !important;
  width: auto !important;
  box-sizing: content-box !important;
  font-family: Monaco, "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
  font-weight: normal !important;
  font-style: normal !important;
  font-size: 15px !important;  /* 这里我改成了15px */
  direction: ltr !important;
  -webkit-box-shadow: none !important;
  -moz-box-shadow: none !important;
  -ms-box-shadow: none !important;
  -o-box-shadow: none !important;
  box-shadow: none !important;
}

.syntaxhighlighter {
  width: 100% !important;
  margin: 1em 0 1em 0 !important;
  padding: 1em !important;    /* 采用黑色背景时,留一点内边距更美观 */
  position: relative !important;
  overflow: auto !important;
  overflow-y: hidden !important;
  font-size: 1em !important;
}
标签: