|
PluginHighlight
KAE.query.highlightKAE.query.highlight is an officially supported plugin, so bug reports belong here. In addition, you can find more technical details at this location.
KAE.query.highlight is very similar to SyntaxHighlighter. In fact, the output looks almost identical. There are many reasons to choose KAE.query.highlight:
Note: some other syntax highlighters (like SHJS) also support some of the above features.
Using KAE.query.highlightHere is a simple example of how to use the plugin (adjust the URLs to your needs): <head>
<link type="text/css" rel="stylesheet" href="KAE.query.highlight.css">
<link type="text/css" rel="stylesheet" href="Themes/theme_Default.css">
</head>
<body>
<script src="KAE.query.highlight.all.js"></script>
<script src="Brushes/brush_JavaScript.js"></script>
<script>
KAE.query("pre").highlight("js");
</script>
</body>And here is what it is doing:
Note: It is recommended to place the <script> tags right before </body>, as this improves the responsiveness of the page. Note: Because it is built on KAE.query, you can use KAE.query.highlight on any element. Note: The first argument is a string describing which brush to use. The "js" brush is defined in the brush_JavaScript.js file. In other words: the above will apply the JavaScript brush to all the <pre> elements in the page.
KAE.query.highlight InterfaceArguments
KAE.query("pre").highlight("js");KAE.query("pre").highlight(["js", "html"]);KAE.query("pre").highlight("js", {
enclosed: false,
toolbar: false
});Examples of UseBackwards compatibility with SyntaxHighlighterLoad KAE.query.highlight like usual (see Using KAE.query.highlight above). Then, load the SyntaxHighlighter.compat.js file. You can now call SyntaxHighlighter.all(). Your settings should Just Work, including any settings placed on the actual elements. It should look something like this: <head>
<link type="text/css" rel="stylesheet" href="KAE.query.highlight.css">
<link type="text/css" rel="stylesheet" href="Themes/theme_Default.css">
</head>
<body>
<script src="KAE.query.highlight.all.js"></script>
<script src="Brushes/brush_JavaScript.js"></script>
<script src="SyntaxHighlighter.compat.js"></script>
<script>
SyntaxHighlighter.defaults["gutter"] = false;
SyntaxHighlighter.all();
</script>
</body>
Normal code<pre>
var obj = {};
</pre>Nothing fancy, just call it like normal: KAE.query("pre").highlight("js");
JavaScript + HTML code<pre>
<script>
var obj = {};
</script>
</pre>In this case, we simply tell it to use both the "js" and "html" brushes: KAE.query("pre").highlight(["js", "html"]);
Code placed inline with normal textYou can create a new object with <code>var obj = {};</code>. In this case, it would be preferable to turn enclosed and toolbar to false: KAE.query("code").highlight("js", {
enclosed: false,
toolbar: false
});
|