https://github.com/gadicc/meteor-syntaxhighlighter
Alex Gorbatchev SyntaxHighlighter, *client-side*
https://github.com/gadicc/meteor-syntaxhighlighter
Last synced: 8 months ago
JSON representation
Alex Gorbatchev SyntaxHighlighter, *client-side*
- Host: GitHub
- URL: https://github.com/gadicc/meteor-syntaxhighlighter
- Owner: gadicc
- Created: 2013-07-04T08:32:00.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2014-09-25T08:40:46.000Z (over 11 years ago)
- Last Synced: 2025-02-17T21:19:16.036Z (over 1 year ago)
- Language: CSS
- Size: 443 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
Awesome Lists containing this project
README
# SyntaxHighlighter
A smart package providing Alex Gorbatchev's [SyntaxHighlighter](http://alexgorbatchev.com/SyntaxHighlighter/) on the **client** side.
For the server side, just use the node-syntaxhighlighter npm package.
If you have `sp-marked` installed too, SyntaxHighlighter sets itself as the
default highlighter, and will be used automatically with no additional work
on your part in ```js type markdown escapes.
## Usage
### Method 1: Our way (recommended)
Use in a template like this:
```html
{{#sh_highlight lang="js"}}function etc() { ... }{{/sh_highlight}}
```
Or directly in Javascript thus:
```js
var highlighted = sh_highlight(text, lang);
```
### Method 2: Use as "normal" (I don't recommend this)
If you format your <pre> blocks as recommend in the apps documentation, just run SyntaxHighlighter.all() in your template's rendered function. e.g.
```js
Template.example.rendered = function() {
SyntaxHighlighter.all();
}
```
### Method 3: For reference, the code used in our helpers
```js
// helper function to choose the right brush
function findBrush(lang) {
for (brush in SyntaxHighlighter.brushes)
for (var i=0; i < SyntaxHighlighter.brushes[brush].aliases.length; i++)
if (SyntaxHighlighter.brushes[brush].aliases[i] == lang)
return SyntaxHighlighter.brushes[brush];
return false;
}
// e.g. var highlighted_code = highlight(code, 'js');
highlight = function(code, lang) {
var brush = findBrush(lang);
if (brush) {
var highlighter = new brush();
highlighter.init();
return highlighter.getHtml(code);
} else {
return code;
}
// example to plug into the marked smart package
marked.setOptions({
highlight: highligh
});
```
## Smart package info
1. On deploy, this sends a minified version of all brushes. It would be preferable to load brushes on demand, but this would require support for static assets in smart packages, which I don't believe exists (yet).