基本信息
源码名称:SyntaxHighlighter 代码高亮 示例源码
源码大小:0.07M
文件格式:.zip
开发语言:js
更新时间:2018-06-17
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>在线代码着色工具</title>
<script src="../statics/js/jquery-1.8.3.min.js"></script>
</head>
<body>
<link id="css" rel="stylesheet" type="text/css" href="css/shCoreDefault.css"/>
<script src="js/shCore.js"></script>
<script src="js/shBrushAll.js"></script>
<script>
var cookieOptions = {
hoursToLive: 30 * 24
}
var REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g;
function encodeHtml(s){
return (typeof s != "string") ? s :
s.replace(REGX_HTML_ENCODE,
function($0){
var c = $0.charCodeAt(0), r = ["&#"];
c = (c == 0x20) ? 0xA0 : c;
r.push(c); r.push(";");
return r.join("");
});
}
function change(type){ //更改样式
var css=document.getElementById("css");
if ("default"==type)
css.setAttribute("href","css/shCoreDefault.css");
if ("emacs"==type)
css.setAttribute("href","css/shCoreEmacs.css");
if ("django"==type)
css.setAttribute("href","css/shCoreDjango.css");
if ("eclipse"==type)
css.setAttribute("href","css/shCoreEclipse.css");
if ("fadetogrey"==type)
css.setAttribute("href","css/shCoreFadeToGrey.css");
if ("mdultra"==type)
css.setAttribute("href","css/shCoreMDUltra.css");
if ("midnight"==type)
css.setAttribute("href","css/shCoreMidnight.css");
if ("rdark"==type)
css.setAttribute("href","css/shCoreRDark.css");
render();
}
$(document).ready(function (){
$("#html_div").hide();
SyntaxHighlighter.all();
$(":radio").click(function (){
change($(this).val());
});
$("#to_html").click(function (){
if($("#to_html").attr("checked")){
toHTML();
$("#html_div").show();
}
else{
$("#html_div").hide();
}
});
$("#gutter").click(function (){
render();
});
});
function render(){
$("#result_div").empty();
$("#result_div").prepend("<pre>" encodeHtml($("#code_source").val()) "</pre>");
var class_v="brush :" $("#code_type").val() ";";
if("checked"!=$("#gutter").attr("checked"))
class_v=class_v "gutter: false;";
$("#result_div pre").addClass(class_v);
SyntaxHighlighter.highlight();
toHTML();
}
function toHTML(){
var html="<link rel='stylesheet' type='text/css' href='http://chaping.github.io/highlight/";
html=html $("#css").attr("href");
html=html "'/>";
html=html $(".syntaxhighlighter").parent().html();
$("#html_div textarea").val(html);
if($("#to_html").attr("checked"))
{
$("#html_div").show();
}
else{
$("#html_div").hide();
}
}
</script>
<div id="mainContent" class="tool_content wrapper" style="width:1000px; margin:0 auto;">
<div class="toolName" style="color:#5B1E2F; font-size:16px; margin:10px;"><strong>在线代码着色(采用SyntaxHighlighter实现)</strong></div>
<div class="toolUsing clearfix">
</div>
<div class="topBar">
<textarea id="code_source" style="width:98%; overflow:auto; height:150px; box-shadow:0 1px 1px inset rgba(0,0,0,0.075); border-radius:3px;">
/* ---示例代码----*/
function echo (){
var a="this is a example";
alert("hello world " a);
}
/* ---示例代码----*/
</textarea>
</div>
<div class="operateTB">
<form class="form-inline">
<select id="code_type" class="span2">
<option value="js">Javascript</option>
<option value="xml">HTML/XML</option>
<option value="java">Java</option>
<option value="c">C/C /Objectiv-C</option>
<option value="ruby">Ruby</option>
<option value="csharp">C#</option>
<option value="css">CSS</option>
<option value="delphi">Delphi</option>
<option value="erlang">Erlang</option>
<option value="groovy">Groovy</option>
<option value="javafx">JavaFX</option>
<option value="perl">Perl</option>
<option value="php">PHP</option>
<option value="powershell">PowerShell</option>
<option value="python">Python</option>
<option value="scala">Scala</option>
<option value="sql">SQL</option>
<option value="vb">VB</option>
<option value="as3">AS3</option>
<option value="bash">Bash</option>
<option value="coldfusion">ColdFusion</option>
<option value="diff">Diff</option>
<option value="plain">Plain</option>
<option value="sass">Sass</option>
</select>
<label class="checkbox"><input type="checkbox" id="gutter" checked="checked"/>显示行号</label>
<label class="checkbox"><input type="checkbox" id="to_html"/>生成HTML</label>
<button type="button" class="btn btn-primary" onClick="render();"><i class="icon-chevron-down icon-white"></i>语法着色</button><p>
<label class="radio"><input type="radio" name="higilight_style" checked="checked" value="default"/>默认样式</label>
<label class="radio"><input type="radio" name="higilight_style" value="emacs"/>Emacs样式</label>
<label class="radio"><input type="radio" name="higilight_style" value="eclipse"/>Eclipse样式</label>
<label class="radio"><input type="radio" name="higilight_style" value="django"/>Django样式</label>
<label class="radio"><input type="radio" name="higilight_style" value="fadetogrey"/>FadeToGrey样式</label>
<label class="radio"><input type="radio" name="higilight_style" value="mdultra"/>MDUltra样式</label>
<label class="radio"><input type="radio" name="higilight_style" value="midnight"/>Midnight样式</label>
<label class="radio"><input type="radio" name="higilight_style" value="rdark"/>RDark样式</label>
</form>
</div>
<div class="bottomBar clearfix">
<div id='html_div'>
<textarea id='html' onclick='this.focus();this.select();' style="width:100%; overflow:auto; height:100px; box-shadow:0 1px 1px inset rgba(0,0,0,0.075); border-radius:3px;">
</textarea>
</div>
<div id="result_div">
<pre class='brush: js;'>
/* ---示例代码----*/
function echo (){
var a="this is a example";
alert("hello world " a);
}
/* ---示例代码----*/
</pre>
</div>
</div>
</div>
</body>
</html>