您现在的位置是:首页 > cms教程 > 帝国CMS教程帝国CMS教程
帝国cms高亮代码添加行号前端显示Mac OS风格
小张2025-09-18帝国CMS教程已有人查阅
导读在我们使用codesnippet插件实现高亮代码后,但有又发现,不太美观和不便于查看,于是就给高亮代码加上行号,怎么给code snippet添加行号。思路:使用js代码增加给高亮代码增加ul和li的无序列表结构,实现行。
在我们使用codesnippet插件实现高亮代码后,但有又发现,不太美观和不便于查看,于是就给高亮代码加上行号,和更好看的Mac OS风格。
这里我贴出css,自己命名然后在头部引用。
步骤一:添加js代码
把以下代码添加到内容模板文件的head之中js文件中,使用js文件引入;
1. 一定要使用引入的形式,不能直接写在模板里,帝国cms会转义反斜杆,造成代码错乱。
2. 一定要在网站的jquery库下面,否则不起作用
步骤二:在高亮代码样式中写入css代码
这里我贴出css,自己命名然后在头部引用。
code[class*="language-"],
pre[class*="language-"] {
color: #f8f8f2;
background: none;
text-shadow: 0 1px rgba(0, 0, 0, 0.3);
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.6;
-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;
border-radius: 0.3em;
}
:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #272822;
}
/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}
.token.punctuation {
color: #f8f8f2;
}
.namespace {
opacity: .7;
}
.token.property,
.token.tag,
.token.constant,
.token.symbol,
.token.deleted {
color: #f92672;
}
.token.boolean,
.token.number {
color: #ae81ff;
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #a6e22e;
}
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string,
.token.variable {
color: #f8f8f2;
}
.token.atrule,
.token.attr-value,
.token.function,
.token.class-name {
color: #e6db74;
}
.token.keyword {
color: #66d9ef;
}
.token.regex,
.token.important {
color: #fd971f;
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}
pre[class*="language-"].line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}
pre[class*="language-"].line-numbers > code {
position: relative;
white-space: inherit;
}
.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em; /* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.line-numbers-rows > span {
pointer-events: none;
display: block;
counter-increment: linenumber;
}
.line-numbers-rows > span:before {
content: counter(linenumber);
color: #999;
display: block;
padding-right: 0.8em;
text-align: right;
}
div.code-toolbar {
position: relative;
}
div.code-toolbar > .toolbar {
position: absolute;
top: .3em;
right: .2em;
transition: opacity 0.3s ease-in-out;
opacity: 0;
width: auto;
background: transparent;
}
div.code-toolbar:hover > .toolbar {
opacity: 1;
}
div.code-toolbar > .toolbar .toolbar-item {
display: inline-block;
margin-right:5px;
}
/*div.code-toolbar > .toolbar a {
cursor: pointer;
}
*/
div.code-toolbar > .toolbar button {
background: none;
border: 0;
color: inherit;
font: inherit;
line-height: normal;
overflow: visible;
padding: 0;
-webkit-user-select: none; /* for button */
-moz-user-select: none;
-ms-user-select: none;
}
div.code-toolbar > .toolbar a,
div.code-toolbar > .toolbar button,
div.code-toolbar > .toolbar span {
color: #F44336;
font-size: .8em;
padding: 0 .5em;
background: #f5f2f0;
background: rgba(224, 224, 224, 0.2);
box-shadow: 0 2px 0 0 rgba(0,0,0,0.2);
border-radius: .5em;
text-decoration:none;
}
div.code-toolbar > .toolbar a:hover,
div.code-toolbar > .toolbar a:focus,
div.code-toolbar > .toolbar button:hover,
div.code-toolbar > .toolbar button:focus,
div.code-toolbar > .toolbar span:hover,
div.code-toolbar > .toolbar span:focus {
color: #FAFAFA;
/*color: inherit;*/
text-decoration: none;
}
/**/
pre[class*="language-"].line-numbers {
padding-top:40px;
/*为了加语言导航条*/
line-height:1.6;
background: #21252b;
box-shadow: 0 10px 30px 0px rgba(0,0,0,.4);
font: 12px "Microsoft YaHei", Arial, Sans-Serif;
margin-bottom: 10px;
max-width: 100%;
overflow: auto;
text-shadow: none;
color: #000;
padding-top: 30px;
box-shadow: 0 10px 30px 0 rgba(0, 0, 0, .4);
}
.pure-highlightjs[class*="language-"]:before {
text-transform: uppercase;
color:#ffffff;
height: 38px;
line-height: 38px;
font-size: 14px;
position: absolute;
top: 0;
left: 0;
font-family: 'Source Sans Pro', sans-serif;
font-weight: 700;
padding: 0 80px;
text-indent: 15px;
float: left;
}
.pure-highlightjs[class*="language-"]:after {
content: " ";
position: absolute;
-webkit-border-radius: 50%;
border-radius: 50%;
background: #fc625d;
width: 12px;
height: 12px;
top: 0;
left: 20px;
margin-top: 13px;
-webkit-box-shadow: 20px 0 #fdbc40, 40px 0 #35cd4b;
box-shadow: 20px 0 #fdbc40, 40px 0 #35cd4b;
}
.try-code-btn {
display: block;
margin: 10px 0;
padding: 8px 15px;
background: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.try-code-btn:hover {
background: #45a049;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
如果行号不显示,也可以按下面的步骤进行。步骤一:添加js代码
把以下代码添加到内容模板文件的head之中js文件中,使用js文件引入;
$(function () {
$("code").each(function () {
$(this).html("<ul id=\'codeblock'><li>" + $(this).html().replace(/\n/g, "\n</li><li>") + "\n</li></ul>");
});
});
注意:1. 一定要使用引入的形式,不能直接写在模板里,帝国cms会转义反斜杆,造成代码错乱。
2. 一定要在网站的jquery库下面,否则不起作用
步骤二:在高亮代码样式中写入css代码
.hljs {
display: block;
padding: 0.5em 0 0.5em 0.5em;
background: #fff;
border: solid 1px #DEE1E6;
border-radius: 3px;
white-space: pre-wrap;
word-break: break-all;
}
/*add line number start*/
.hljs ul {
margin-left: 40px;
}
.hljs ul li {
border-left: solid 1px #DEE1E6;
padding: 3px;
list-style: decimal-leading-zero;/*0开头的数字标记。(01, 02, 03, 等。)*/
}
.hljs ul li:nth-child(even) {/*偶数行的背景颜色*/
background-color: #F7F7F7;
}
/*add line number end*/
注意注意事项:高亮样如果是monokai_sublime,大家把我的代码复制过去只用修改颜色就行了。
本文标签:帝国建站
很赞哦! ()
图文教程
帝国CMS列表/标签/JS怎么支持置顶的方法
帝国CMS有置顶的功能,可以将信息设置置顶。 但列表页、标签调用、JS调用却不支持置顶排前面。这是因为帝国CMS默认没有开启置顶排序功能。 通过以下方法开启: 系统参数设置--
帝国CMS制作字母导航功能的方法
也许你想制作像58同城网城市分站一样的字母导航功能,帝国CMS当然是可以实现的。增加“infozm”字段,infozm为取得标题字母的字段,只需将字段设置为录入项或投稿项
帝国CMS实现tagid伪静态tag的步骤教程
搜索“function eReturnRewriteTagsUrl($tagid,$tagname,$ecms=0){”找到函数eReturnRewriteTagsUrl,将此函数删除或注释掉,换成下面的代码:
帝国CMS怎么自动审核文章,帝国CMS自动审核发布信息脚本
此功能已有插件,插件更好用。当一个站大量采集信息,一次发布不利于长期SEO,所以从网上找了这个脚本稍作修改。分享给大家,其实也很简单,但比帝国自带的计划任务功能好的是
相关源码
-
(自适应)品牌策划高端设计公司网站pbootcms模板免费下载本模板为品牌策划与设计公司打造,基于PbootCMS内核开发,充分考虑了创意设计行业的视觉展示需求。模板设计风格现代简约,布局合理清晰,呈现设计作品与专业服务,帮助设计公司展示创意实力并吸引潜在客户。查看源码 -
(PC+WAP)蓝色钢结构机械五金工程建筑基建营销型pbootcms模板下载于PbootCMS开发的钢结构与工程机械专用模板,助力企业构建专业级产品展示平台;模板内置工程案例展示、产品参数对照表等专业模块,预设项目进度、施工方案等建筑行业专属栏目查看源码 -
(PC+WAP)高端餐饮美食小吃加盟网站模板下载pbootcms本模板基于PbootCMS内核开发,为餐饮美食品牌加盟、小吃连锁企业量身打造。通过精致的美食视觉呈现与加盟业务流程展示,帮助餐饮企业建立专业线上门户,实现品牌形象与加盟业务的双重展示。查看源码 -
(自适应响应式)电子数码科技产品介绍带留言网站模板下载为电子产品企业设计的展示系统,集成智能产品对比器、参数规格表和展示模块。支持消费电子、智能设备等多级分类展示,内置产品技术参数数据库。查看源码 -
(自适应响应式)html5文章资讯新闻博客pbootcms网站模板下载本模板基于PbootCMS系统开发,为新闻资讯、博客类网站设计,特别适合各类文章内容的发布与管理。采用响应式技术,确保在不同设备上都能获得良好的阅读体验。查看源码 -
(PC+WAP)玻璃钢不锈钢钢材环保设备pbootcms网站模板采用PbootCMS内核开发的响应式网站模板,为玻璃钢环保设备制造、不锈钢钢材贸易企业设计,适配产品展示及企业服务场景。通过自适应技术实现PC与WAP端数据实时同步查看源码
| 分享笔记 (共有 篇笔记) |

