前言

此 Hugo 模板的語法高亮配色沒有深得我心,研究了一下發現它是用 Prism.js 實現的。

所以修改了配色,順手將 Prism.js 更新到最新版,也刪減了一些沒有用到的語言,使其更為精簡。


關於 Prism.js

Prism.js 是一種輕量級,可擴展的語法高亮解析器,依據現代 Web 標準構建。

它已在數千個網站中使用,包括您每天訪問的一些網站。


安裝 Prism.js

  1. 進入 官網 勾選所需語言與主題,下載 JS、CSS 檔放入網站目錄。

  2. 於網站<body>中導入 JS 檔:

    <script src="{{ "assets/prism.js" | absURL }}"></script>
    

    ``

  3. 於網站<head>中導入 CSS 檔:

    <link rel="stylesheet" href="{{ "assets/prism.css" | absURL }}">
    

    ``


Atom-Dark.css

由於沒有很滿意官方主題的配色與字型,所以自行修改製作了 Atom-Dark 版本:

/* PrismJS 1.17.1*/
/**
 * prism.js tomorrow night eighties for JavaScript, CoffeeScript, CSS and HTML
 * Based on https://github.com/chriskempson/tomorrow-theme
 * @author Rose Pritchard
 */

code[class*="language-"],pre[class*="language-"] {
	/* color: #ccc; */
	background: none;
	font-family: Menlo, Consolas, 'Ubuntu Mono', monospace;
	/* font-size: 1em; */
	text-align: left;
	white-space: pre;
	word-spacing: normal;
	word-break: normal;
	word-wrap: normal;
	line-height: 1.5;

	-moz-tab-size: 4;
	-o-tab-size: 4;
	tab-size: 4;

	-webkit-hyphens: none;
	-moz-hyphens: none;
	-ms-hyphens: none;
	hyphens: none;

}

/* Code blocks */
/* pre[class*="language-"] {
	padding: 1em;
	margin: .5em 0;
	overflow: auto;
} */

:not(pre) > code[class*="language-"],pre[class*="language-"] {
	background:#212020!important;
	border-radius:8px;
	color:inherit!important;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
	padding: .1em;
	border-radius: .3em;
	white-space: normal;
}

.token.comment,
.token.block-comment,
.token.prolog,
.token.doctype,
.token.cdata {
	color: #5c6370;
	font-weight: bold;
	font-style: italic;
}

.token.punctuation {
	color: #abb2bf;
}

.token.tag,
.token.attr-name,
.token.namespace,
.token.deleted,
.token.interpolation,
.token.interpolation-punctuation {
	color: #e06c75;
}

.token.function-name,
.token.function {
	color: #61aeee;
}

.token.boolean,
.token.number {
	color: #d19a66;
}

.token.property,
.token.class-name,
.token.constant,
.token.symbol {
	color: #e6c07b;
}

.token.selector,
.token.important,
.token.atrule,
.token.keyword,
.token.builtin {
	color: #c678dd;
}

.token.string,
.token.char,
.token.attr-value,
.token.regex,
.token.variable {
	color: #98c379;
}

.token.operator,
.token.entity,
.token.url {
	color: #56b6c2;
}

.token.important,
.token.bold {
	font-weight: bold;
}
.token.italic {
	font-style: italic;
}

.token.entity {
	cursor: help;
}

.token.inserted {
	color: green;
}