修改并上传SyntaxHighlighter源码个性化博客代码风格
或许是我太苛刻了,用了博客园默认的SyntaxHighlighter工具高亮代码后,总不尽人意。首先是行间距太大,这对于只贴小量的代码没什么问题。但如果代码很长,将会很大程度上影响阅读效率。其次,博客园似乎修改了SyntaxHighlighter原版代码不能自动换行的问题,但改得不彻底,又引出了新的问题:自动换行后会导致行号不连惯,并且产生多行注释时的Bug。
但也有改的好的地方,比如字体比原来默认的漂亮多了,高亮的颜色也更加符合阅读习惯,还有就是给代码的行加上了两种不同的背景色,交替显示,这都让代码看起来舒爽了很多。
最后,我还是决定自己动手,查找资料,上传并修改SyntaxHighlighter源码,基本上达到了预期的目标。
1.下载并修改SyntaxHighlighter源码
1.1下载SyntaxHighlighter
可到http://alexgorbatchev.com/SyntaxHighlighter/下载SyntaxHighlighter。我下的是8.0.83版本。
1.2 修改源码
找到styles/shCoreDefault.css文件,按照如下方式修改:
/*** SyntaxHighlighter* http://alexgorbatchev.com/SyntaxHighlighter** SyntaxHighlighter is donationware. If you are using it, please donate.* http://alexgorbatchev.com/SyntaxHighlighter/donate.html** @version* 3.0.83 (July 02 2010)* * @copyright* Copyright (C) 2004-2010 Alex Gorbatchev.** @license* Dual licensed under the MIT and GPL licenses.*/
.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.1em !important; */line-height: 1.2em !important;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: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; */font-family: "新宋体", Courier, monospace !important;font-weight: normal !important;font-style: normal !important;/* 修改字体大小 *//* font-size: 1em !important; */font-size: 13px !important;min-height: inherit !important;min-height: auto !important;
}.syntaxhighlighter {width: 100% !important;margin: 1em 0 1em 0 !important;position: relative !important;overflow: auto !important;/* 修改字体大小,此处没明显效果 *//* font-size: 1em !important; */font-size: 13px !important;
}
.syntaxhighlighter.source {overflow: hidden !important;
}
.syntaxhighlighter .bold {font-weight: bold !important;
}
.syntaxhighlighter .italic {font-style: italic !important;
}
.syntaxhighlighter .line {white-space: pre !important;
}
.syntaxhighlighter table {width: 100% !important;/* 给代码加个框框 */border: 1px solid #7FFFD4 !important;
}
.syntaxhighlighter table caption {text-align: left !important;padding: .5em 0 0.5em 1em !important;
}
.syntaxhighlighter table td.code {width: 100% !important;
}
.syntaxhighlighter table td.code .container {position: relative !important;
}
.syntaxhighlighter table td.code .container textarea {box-sizing: border-box !important;position: absolute !important;left: 0 !important;top: 0 !important;width: 100% !important;height: 100% !important;border: none !important;background: white !important;padding-left: 1em !important;overflow: hidden !important;white-space: pre !important;
}
.syntaxhighlighter table td.gutter .line {text-align: right !important;padding: 0 0.5em 0 1em !important;
}
.syntaxhighlighter table td.code .line {padding: 0 1em !important;
}
.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {padding-left: 0em !important;
}
.syntaxhighlighter.show {display: block !important;
}
.syntaxhighlighter.collapsed table {display: none !important;
}
.syntaxhighlighter.collapsed .toolbar {padding: 0.1em 0.8em 0em 0.8em !important;font-size: 1em !important;position: static !important;width: auto !important;height: auto !important;
}
.syntaxhighlighter.collapsed .toolbar span {display: inline !important;margin-right: 1em !important;
}
.syntaxhighlighter.collapsed .toolbar span a {padding: 0 !important;display: none !important;
}
.syntaxhighlighter.collapsed .toolbar span a.expandSource {display: inline !important;
}
.syntaxhighlighter .toolbar {position: absolute !important;right: 1px !important;top: 1px !important;width: 11px !important;height: 11px !important;font-size: 10px !important;z-index: 10 !important;
}
.syntaxhighlighter .toolbar span.title {display: inline !important;
}
.syntaxhighlighter .toolbar a {display: block !important;text-align: center !important;text-decoration: none !important;padding-top: 1px !important;
}
.syntaxhighlighter .toolbar a.expandSource {display: none !important;
}
.syntaxhighlighter.ie {font-size: .9em !important;padding: 1px 0 1px 0 !important;
}
.syntaxhighlighter.ie .toolbar {line-height: 8px !important;
}
.syntaxhighlighter.ie .toolbar a {padding-top: 0px !important;
}
.syntaxhighlighter.printing .line.alt1 .content,
.syntaxhighlighter.printing .line.alt2 .content,
.syntaxhighlighter.printing .line.highlighted .number,
.syntaxhighlighter.printing .line.highlighted.alt1 .content,
.syntaxhighlighter.printing .line.highlighted.alt2 .content {background: none !important;
}
.syntaxhighlighter.printing .line .number {color: #bbbbbb !important;
}
.syntaxhighlighter.printing .line .content {color: black !important;
}
.syntaxhighlighter.printing .toolbar {display: none !important;
}
.syntaxhighlighter.printing a {text-decoration: none !important;
}
.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {color: black !important;
}
.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {color: #008200 !important;
}
.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {color: blue !important;
}
.syntaxhighlighter.printing .keyword {color: #006699 !important;font-weight: bold !important;
}
.syntaxhighlighter.printing .preprocessor {color: gray !important;
}
.syntaxhighlighter.printing .variable {color: #aa7700 !important;
}
.syntaxhighlighter.printing .value {color: #009900 !important;
}
.syntaxhighlighter.printing .functions {color: #ff1493 !important;
}
.syntaxhighlighter.printing .constants {color: #0066cc !important;
}
.syntaxhighlighter.printing .script {font-weight: bold !important;
}
.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {color: gray !important;
}
.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {color: #ff1493 !important;
}
.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {color: red !important;
}
.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {color: black !important;
}.syntaxhighlighter {background-color: white !important;
}
.syntaxhighlighter .line.alt1 {/* 行颜色交替变换显示设置,与下面的alt2配合 *//* background-color: white !important; */background-color: #f8f8f8 !important;
}
.syntaxhighlighter .line.alt2 {background-color: white !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {background-color: #e0e0e0 !important;
}
.syntaxhighlighter .line.highlighted.number {color: black !important;
}
.syntaxhighlighter table caption {color: black !important;
}
.syntaxhighlighter .gutter {color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {border-right: 3px solid #6ce26c !important;
}
.syntaxhighlighter .gutter .line.highlighted {background-color: #6ce26c !important;color: white !important;
}
.syntaxhighlighter.printing .line .content {border: none !important;
}
.syntaxhighlighter.collapsed {overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {color: blue !important;background: white !important;border: 1px solid #6ce26c !important;
}
.syntaxhighlighter.collapsed .toolbar a {color: blue !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {color: red !important;
}
.syntaxhighlighter .toolbar {/* 去掉右上角的小问号(2-1),应根据行交替显示的颜色设置该选项 *//* color: white !important; *//* background: #6ce26c !important; */color: white !important;background: white !important;border: none !important;
}
.syntaxhighlighter .toolbar a {/* 2-2去掉右上角的小问号(2-2) *//* color: white !important; */color:white !important;
}
.syntaxhighlighter .toolbar a:hover {color: black !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {color: black !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {color: #008200 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {/* 修改字符串值的颜色 *//* color: blue !important; */color: #a31414 !important;
}
.syntaxhighlighter .keyword {/* 修改关键字的颜色 *//* color: #006699 !important; */color: blue !important;
}
.syntaxhighlighter .preprocessor {/* 修改预处理的颜色 *//* color: gray !important; */color: #02027e !important;
}
.syntaxhighlighter .variable {color: #aa7700 !important;
}
.syntaxhighlighter .value {color: #009900 !important;
}
.syntaxhighlighter .functions {/* 禁止系统函数加粗显示 */font-weight: normal !important; color: #ff1493 !important;
}
.syntaxhighlighter .constants {color: #0066cc !important;
}
.syntaxhighlighter .script {font-weight: bold !important;color: #006699 !important;background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {/* 禁止数据类型加粗显示 */font-weight: normal !important; /* 修改数据类型的颜色 *//* color: gray !important; */color: #a300a3 !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {color: #ff1493 !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {color: red !important;
}.syntaxhighlighter .keyword {/* 取消关键字加粗显示 *//* font-weight: bold !important; */font-weight: normal !important;
}
这里并没有添加自动换行的功能,暂时先在写博客时手动调整一下单行代码的长度,别越界就OK了。
2.上传源码并在Blog中设置
2.1上传文件
需要上传两种类型的文件:
- css文件,将刚刚修改好的shCoreDefault.css上传即可。
- js文件,shCore.js是必传的,另外再可以有选择性的上传你需要的文件。比如我常用C++,偶尔用css,那么就可以只上传shBrushCpp.js和shBrushCss.js两个文件。当然,也可以全部js文件都传上去。
如图(我只上传了部分文件):
2.2 设置Blog.
这一步的主要目的是在合适的位置添加合适的源码,使你刚刚上传的源码文件发挥作用。你需要在博客园-->设置-->子标题中添加如图所示代码:
全部代码为:
<script type="text/javascript"
src="http://files.cnblogs.com/chinaxmly/shCore.js"></script>
<script type="text/javascript"
src="http://files.cnblogs.com/chinaxmly/shBrushCpp.js"></script>
<script type="text/javascript"
src="http://files.cnblogs.com/chinaxmly/shBrushCss.js"></script>
<script type="text/javascript"
src="http://files.cnblogs.com/chinaxmly/shBrushXml.js"></script>
<script type="text/javascript"
src="http://files.cnblogs.com/chinaxmly/shBrushJScript.js"></script>
<link type="text/css" rel="stylesheet"
href="http://files.cnblogs.com/chinaxmly/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.config.strings.help = "";SyntaxHighlighter.config.strings.expandSource = "+ 查看代码";SyntaxHighlighter.all();
</script>
说明:
- herf和src的值为你的博客地址加文件名称。
- “SyntaxHighlighter.config.strings.help = “”;”这句话用于去掉代码右上角的小‘?’号。
3. 个性化代码风格
将你的代码包含在如下的<pre></pre>标签中即可:
<pre class="brush: cpp; highlight: [12, 15]; first-line: 10; html-script: false; light: false; auto-links: false; collapse: true; class-name: 'class_name_demo';">
// 你的代码
</pre>
最终的效果如下所示(C++):
// 程序初始化仿真#define TRUE 1
#define FALSE 0typedef char* LPSTR;
typedef const char* LPCSTR;#include <iostream>using namespace std;///
// Window message map handling
struct AFX_MSGMAP_ENTRY; // declared below after CWndstruct AFX_MSGMAP
{AFX_MSGMAP* pBaseMessageMap;AFX_MSGMAP_ENTRY* lpEntries;
};// DECLARE_MESSAGE_MAP
#define DECLARE_MESSAGE_MAP() \static AFX_MSGMAP_ENTRY _messageEntries[]; \static AFX_MSGMAP messageMap; \virtual AFX_MSGMAP* GetMessageMap() const;/* 多行代码示例 */
class CFrameWnd : public CWnd uuuuuuuuuuuuuuuuuuuuuyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyiuojfosfejosifoefsfijsojuosfa;fslfjeosjfoaifjeojsosjfessfeoij
{
public: CFrameWnd() { }~CFrameWnd() { }virtual BOOL Create();virtual BOOL PreCreateWindow();
};/* 单行注释 *//*
* 多行注释
*/class CView : public CWnd
{
public:CView() { }~CView() { }
};BOOL CWnd::CreateEx()
{int x = 7;x++;char* = "Hello World.";PreCreateWindow();// 系统函数ps1 = (char *)malloc(10); // 在堆区分配10个字节ps2 = (char *)malloc(20); // 在堆区分配20个字节return TRUE;
}
转载于:https://www.cnblogs.com/chinaxmly/archive/2012/09/27/2706359.html
修改并上传SyntaxHighlighter源码个性化博客代码风格相关推荐
- 分享66个ASP上传下载源码,总有一款适合您
分享66个ASP上传下载源码,总有一款适合您 66个ASP上传下载源码下载链接:https://pan.baidu.com/s/1AAZA99BVNOFtVFIjnYl4XA?pwd=vyqa 提取 ...
- 分享111个ASP上传下载源码,总有一款适合您
分享111个ASP上传下载源码,总有一款适合您 111个ASP上传下载源码下载链接:https://pan.baidu.com/s/1VaiX2JZqyBue8g_x7bsrZA?pwd=szji ...
- 分享116个ASP上传下载源码,总有一款适合您
分享116个ASP上传下载源码,总有一款适合您 116个ASP上传下载源码下载链接:https://pan.baidu.com/s/1loHIyl9LUAkyPBedFpkRQw?pwd=fflw ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(32)-swfupload多文件上传[附源码]...
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(32)-swfupload多文件上传[附源码] 文件上传这东西说到底有时候很痛,原来的asp.net服务器 ...
- 小程序 多张图片上传(源码分享+实现分析)
本篇文章以小程序中的代表[微信小程序]为例,分享一下在微信小程序中实现多图上传的源码实现. PS:其它小程序 和 uni-app 也可通用该思路实现. 代码片段(可导入微信WEB开发者工具体验):ht ...
- QQ透明名片在线上传网站源码
介绍: 最近超流行的QQ透明名片,无需复杂操作,不需要QQ会员,一键就能制作自己的专属名片,超高逼格. 透明名片在线上传网站源码 注意事项 1.名片必须恢复默认 2.图片不能太大,过大可以找个好友发 ...
- jQuery图片批量上传插件源码,支持批量上传、预览、删除、放大,可配置上传数量、上传大小、追加方式,含详细使用文档
jQuery图片批量上传插件源码,支持批量上传.预览.删除.放大,可配置上传数量.上传大小.追加方式,含详细使用文档 程序包内含使用Demo 完整程序源代码:jQuery图片批量上传插件源码 上传前 ...
- 芋道源码 -- 纯源码解析博客
本文转载: 原文地址: 芋道源码 -- 纯源码解析博客
- SAE利用storge上传文件 - myskies的专栏 - 博客频道 - CSDN.NET
SAE利用storge上传文件 - myskies的专栏 - 博客频道 - CSDN.NET SAE利用storge上传文件
最新文章
- getElementsByName,实现多选的全选与全不选功能
- Centos7 关闭防火墙(转)
- 重写,重载,抽象类,接口,抽象类和接口区别
- 在学习django的时候
- 定理在数学中的简写形式_西方把勾股定理叫毕达哥拉斯定理,我们的教材上是不是该改改名?...
- python实现冒泡排序算法的非递归版本_python排序算法速度比较:快速排序,归并排序,冒泡排序...
- 还是树形dp 也可以用最短路来写--NOJ679 贪婪的商店
- 递归2:第 N 个泰波那契数
- 程序员,当你写程序写累了怎么办。
- tomcat中配置jndi数据源以便spring获取
- 【微信小程序】数组操作
- Linux编译soci库,Soci库linux下的编译方法
- xp系统的WINS服务器设置,WindowsXP系统设置
- arm+linux+entry.s,linux kernel 之底层中断机制entry_armv.S
- BCD码和十六进制的区别【转】
- js ajax mysql_Ajax与mysql数据交互实现留言板功能
- Gallery3D笔记
- 最优秀的数据可视化案例欣赏
- 天梯赛+01训练总结
- 在新的固态硬盘中安装windows系统(旧固态硬盘已安装ubuntu系统)
热门文章
- Adobe illustrator 为什么对不齐?AI无法对齐操作?如图我画了一个形状想用园和那条直线对其但是我鼠标拖动智能参考线都已经对齐了 但是松开后又错开了
- 地磁系统相对于机器视觉的优势
- 磁共振血管造影/MRI造影/钡磷灰石显影剂/新型含氟药物氟代吲哚美辛PET显影剂
- 街道道路模型,高架桥模型,摊位模型,毁坏房屋模型等等
- 可视化大数据数据决策分析_通过数据可视化为您的业务做出更好的决策
- maven项目 报错 Lifecycle mapping quot;org.eclipse.m2e.jdt.JarLifecycleMappingquot; is not available.
- 在计算机阅卷过程中存入电脑的过程,中高考电脑阅卷流程曝光!不避开这些“坑”,你就要白白丢分了!...
- 如何使用vscode登陆服务器
- 求解Python 爬取百度翻译手机版{errno:997,from:zh,to:en,query:\u4eba\u751f\u82e6\u77ed}怎么办
- SMTP 协议,验证 Email 地址