您现在的位置是:首页 > 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登陆表单怎么制作示例教程
帝国CMS内置强大的搜索功能,用户只需制作搜索表单指向搜索处理页面即可实现相应搜索。本文讲解:搜索表单制作语法。
帝国CMS二次开发统计留言数量的方法
帝国CMS指定模型下的留言数量 代码:帝国CMS不指定模型留言数量 代码:
帝国cms怎么防止恶意注册 会员空间发布违规违禁信息
最近接到几个客户的反馈:收录的内容出现了类似地址,域名/e/space/?userid=xxx的链接,并且这个链接里面有大量的违法违禁广告词语。
帝国二次开发JS调用登陆模板调用会员头像的方法
打开/e/data/template/loginiframetemp.txt修改成,在JS调用登陆模板使用,同理,还可以调用其他任何会员相关的字段
相关源码
-
(自适应响应式)动力刀座五金机械设备pbootcms网站源码下载为动力刀座及五金机械企业定制的响应式网站框架,基于PbootCMS系统深度开发,助力传统制造企业实现数字化转型升级。采用手工编写的DIV+CSS前端架构,代码执行效率提升40%。查看源码 -
(响应式自适应)小学初中作文论文文章资讯博客pbootcms模板下载为中小学作文、教育类网站设计,特别适合展示学生作文、教学资源和写作指导等内容。采用响应式技术,确保在不同设备上都能获得良好的阅读体验。查看源码 -
(自适应响应式)房产合同知识产权企业管理pbootcms模板下载本模板基于PbootCMS系统开发,为知识产权服务、法律咨询及企业合同管理等行业设计。采用严谨专业的布局风格,突出法律文书与知识产权服务行业特色,适合展示各类法律服务和知识产权相关内容。查看源码 -
pbootcms响应式蓝色旅游旅行社pbootcms网站源码下载为旅游公司、旅行社定制的响应式网站模板,聚焦旅游线路展示、景点推荐及预约服务场景。采用PbootCMS内核开发,自适应技术确保PC与手机端数据实时同步查看源码 -
(自适应)代理记账财务会计咨询服务个人公司网站模板该响应式网站模板为代理记账、财政咨询及财务会计类企业设计,基于PbootCMS内核开发。通过自适应手机端的HTML5技术,帮助企业高效构建专业财税服务平台查看源码 -
(PC+WAP)房屋建造建筑工程房地产建材行pbootcms网站模板下载本模板基于PbootCMS内核开发,为房屋建造、建筑工程及房地产建材类企业设计。通过本模板可快速搭建具有行业特色的企业官网,只需替换文字与图片内容即可适配其他行业使用。查看源码
| 分享笔记 (共有 篇笔记) |

