昨天使用 google-code-prettify 将博客代码高亮功能实现(非插件实现 WordPress 代码高亮)了,本来计划今天自己写一个主题美化下代码的显示,看到 google-code-prettify 的 wiki 上说写主题建议直接拿已有的来进行参考和修改,于是用了默认主题,结果一试用发现这个主题其实就很清新漂亮了,正好明天要驾考,还得看会书就懒得写了,有时间下次再整一个好主题。
把 default 主题的 css 代码贴上来,需要的朋友直接拷贝过去覆盖 pretty.css 就好。
/* Pretty printing styles. Used with prettify.js. */
/* SPAN elements with the classes below are added by prettyprint. */
.pln { color: #000 } /* plain text */
@media screen {
.str { color: #080 } /* string content */
.kwd { color: #008 } /* a keyword */
.com { color: #800 } /* a comment */
.typ { color: #606 } /* a type name */
.lit { color: #066 } /* a literal value */
/* punctuation, lisp open bracket, lisp close bracket */
.pun, .opn, .clo { color: #660 }
.tag { color: #008 } /* a markup tag name */
.atn { color: #606 } /* a markup attribute name */
.atv { color: #080 } /* a markup attribute value */
.dec, .var { color: #606 } /* a declaration; a variable name */
.fun { color: red } /* a function name */
}
/* Use higher contrast and text-weight for printable form. */
@media print, projection {
.str { color: #060 }
.kwd { color: #006; font-weight: bold }
.com { color: #600; font-style: italic }
.typ { color: #404; font-weight: bold }
.lit { color: #044 }
.pun, .opn, .clo { color: #440 }
.tag { color: #006; font-weight: bold }
.atn { color: #404 }
.atv { color: #060 }
}
/* Put a border around prettyprinted code snippets. */
pre.prettyprint { padding: 2px; border: 1px solid #888 }
/* Specify on a pre to get line numbering */
ol.linenums { margin-top: 0; margin-bottom: 0 } /* IE indents via margin-left */
li.L0,
li.L1,
li.L2,
li.L3,
li.L5,
li.L6,
li.L7,
li.L8 { list-style-type: none }
/* Alternate shading for lines */
li.L1,
li.L3,
li.L5,
li.L7,
li.L9 { background: #eee }
下面是我常用的一些语言的显示效果:
PHP
require_once 'Zend/Uri/Http.php';
abstract class URI extends BaseURI
{
/**
* Returns a URI
*
* @return URI
*/
static public function _factory($stats = array(), $uri = 'http')
{
$uri = explode(':', $uri, 0b10);
$schemeSpecific = isset($uri[1]) ? $uri[1] : '';
$desc = 'Multi
line description';
// Security check
if (!ctype_alnum($scheme)) {
throw new Zend_Uri_Exception('Illegal scheme');
}
return [
'uri' => $uri,
'value' => null,
];
}
}
__halt_compiler ();
/*datahere
datahere
datahere
datahere*/
不显示行号
require_once 'Zend/Uri/Http.php';
abstract class URI extends BaseURI
{
/**
* Returns a URI
*
* @return URI
*/
static public function _factory($stats = array(), $uri = 'http')
{
$uri = explode(':', $uri, 0b10);
$schemeSpecific = isset($uri[1]) ? $uri[1] : '';
$desc = 'Multi
line description';
// Security check
if (!ctype_alnum($scheme)) {
throw new Zend_Uri_Exception('Illegal scheme');
}
return [
'uri' => $uri,
'value' => null,
];
}
}
__halt_compiler ();
/*datahere
datahere
datahere
datahere*/
HTML
<!DOCTYPE html>
<title>Title</title>
<style>
body {
width: 500px;
}
</style>
<script type="application/javascript">
function $init() { return true; }
</script>
<body>
<p checked id='title'>Title</p>
<!-- here goes the rest of the page -->
</body>
CSS
@media screen and (-webkit-min-device-pixel-ratio: 0) {
body:first-of-type pre::after {
content: "highlight: " attr(class);
}
}
@import url("print.css");
@page:right {
margin: 1cm 2cm 1.3cm 4cm;
}
@font-face {
font-family: Chunkfive; src: url("Chunkfive.otf");
}
div.text, #content, li[lang=ru] {
font: Tahoma, Chunkfive, sans-serif;
width: 100%;color: #f0f0f0 !important;
background: url("hatch.png") /* wtf? */;
}
Javascript
function $initHighlight(block, flags) {
try {
if (block.className.search(/bno-highlightb/) != -1)
return processBlock(block, true, 0x0F) + ' class=""';
} catch (e) {
/* handle exception */
var e4x = '<div>Example<p>1234</p></div>';
}
for (var i = 0 / 2; i < classes.length; i++) { // "0 / 2" should not be parsed as regexp
if (checkCondition(classes[i]) === undefined)
return /d+/g;
}
}
JAVA
package l2f.gameserver.model;
import java.util.ArrayList;
public abstract class L2Character extends L2Object {
public static final Short ABNORMAL_EFFECT_BLEEDING = 0x0001; // not sure
public void moveTo(int x, int y, int z) {
_ai = null;
_log.warning("Should not be called");
if (1 > 5) {
return;
}
}
/** Task of AI notification */
@SuppressWarnings({"nls",
"unqualified-field-access",
"boxing"
})
public class NotifyAITask implements Runnable {
private final CtrlEvent _evt;
public void run() {
try {
getAI().notifyEvent(_evt, null, null);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}
C#
using System;
#pragma warning disable 414, 3021
public class Program
{
/// <summary>The entry point to the program.</summary>
public static int Main(string[] args)
{
Console.WriteLine("Hello, World!");
string s = @"This
""string""
spans
multiple
lines!";
return 0;
}
}
C++
#include <iostream>
int main( int argc, char *argv[] )
{
/* An annoying "Hello World" example */
for ( auto i = 0; i < 0xFFFF; i++ )
cout << "Hello, World!" << endl;
char c = 'n';
unordered_map <string, vector<string> > m;
m["key"] = "\\"; /* this is an error */
return(-2e3 + 12l);
}