Because the use of syntaxhighlighter will be used in many languages, one must load all the language configuration file download will be more, so Syntaxhighlighter provides a shautoloader.js script. This site is in use, the site code is as follows:
1234567891011121314151617181920212223242526272829303132333435363738394041 |
<script type=
"text/javascript"
src=
"/Themes/BootStrap/scripts/Syntaxhighlighter/scripts/shCore.js"
></script>
<script type=
"text/javascript"
src=
"/Themes/BootStrap/scripts/Syntaxhighlighter/scripts/shAutoloader.js"
></script>
<link type=
"text/css"
rel=
"stylesheet"
href=
"/Themes/BootStrap/scripts/Syntaxhighlighter/styles/shCoreDefault.css"
/>
<script type=
"text/javascript"
>
function
path() {
var args = arguments,
result = [];
for
(
var
i = 0; i < args.length; i++)
result.push(args[i].replace(
‘$‘
,
‘/Themes/BootStrap/scripts/Syntaxhighlighter/scripts/‘
));
return
result
}
$(
function
() {
SyntaxHighlighter.autoloader.apply(
null
, path(
‘applescript $shBrushAppleScript.js‘
,
‘actionscript3 as3 $shBrushAS3.js‘
,
‘bash shell $shBrushBash.js‘
,
‘coldfusion cf $shBrushColdFusion.js‘
,
‘cpp c $shBrushCpp.js‘
,
‘c# c-sharp csharp $shBrushCSharp.js‘
,
‘css $shBrushCss.js‘
,
‘delphi pascal $shBrushDelphi.js‘
,
‘diff patch pas $shBrushDiff.js‘
,
‘erl erlang $shBrushErlang.js‘
,
‘groovy $shBrushGroovy.js‘
,
‘java $shBrushJava.js‘
,
‘jfx javafx $shBrushJavaFX.js‘
,
‘js jscript javascript $shBrushJScript.js‘
,
‘perl pl $shBrushPerl.js‘
,
‘php $shBrushPhp.js‘
,
‘text plain $shBrushPlain.js‘
,
‘py python $shBrushPython.js‘
,
‘ruby rails ror rb $shBrushRuby.js‘
,
‘sass scss $shBrushSass.js‘
,
‘scala $shBrushScala.js‘
,
‘sql $shBrushSql.js‘
,
‘vb vbnet $shBrushVb.js‘
,
‘xml xhtml xslt html $shBrushXml.js‘
));
SyntaxHighlighter.all();
}
</script>
|
However, the article detail page often does not have any code, so these JS files and JS code need to determine whether to execute:
1234567 |
//判断文章是否需要加载代码高亮插件 var isCode = Model.Html.ToString().Contains( "<pre class=\"brush:" ); @{ if (isCode){ //这里放置上面的js文件链接以及js代码。 } } |
This article from: http://www.itdos.com/JavaScript/20150303/0135261.html reproduced please keep this text, thank you!
Syntaxhighlighter-autoloader (auto load)