Add syntax highlighting for c and bash

master
Buddy Sandidge 10 years ago
parent c5829b65ea
commit f7c472d762

@ -12,7 +12,7 @@
return function (prefix) {
prefix = prefix || '';
var langPrefix = prefix + '/vendor/prism/components/prism-';
return {
paths: {
backbone: prefix + '/vendor/backbone/backbone',
@ -21,11 +21,20 @@
jquery: prefix + '/vendor/jquery/dist/jquery',
marionette: prefix + '/vendor/marionette/lib/backbone.marionette',
prism: prefix + '/vendor/prism/prism',
'prism-bash': langPrefix + 'bash',
'prism-c': langPrefix + 'c',
'prism-clike': langPrefix + 'clike',
'prism-javascript': langPrefix + 'javascript',
underscore: prefix + '/vendor/underscore/underscore'
},
shim: {
handlebars: {exports: 'Handlebars'},
prism: {exports: 'Prism'},
'prism-bash': {deps: ['prism', 'prism-clike'], exports: 'Prism'},
'prism-c': {deps: ['prism', 'prism-clike'], exports: 'Prism'},
'prism-clike': {deps: ['prism'], exports: 'Prism'},
'prism-javascript': {deps: ['prism', 'prism-clike'], exports: 'Prism'},
underscore: {exports: '_'}
}
};

@ -1,6 +1,8 @@
define(['prism'], function (Prism) {
return function (text, language) {
define(['prism', 'prism-javascript'], function (Prism) {
return function (text, language, cb) {
language = language || 'javascript';
return Prism.highlight(text, Prism.languages[language]);
require(['prism-' + language], function () {
return cb(Prism.highlight(text, Prism.languages[language]));
});
};
});

@ -39,10 +39,19 @@ define([
if (copy) {
this.ui.copy.html(markdown(copy));
}
var code = this.model.get('code');
if (code) {
this.ui.code.html(syntax(code));
}
this.ui.copy.find('pre > code').each(function (index, el) {
var language = _.reduce(el.classList, function (memo, className) {
if (/language-/.test(className)) {
return className.replace('language-', '');
}
return memo;
}, '');
var $el = $(el);
syntax($el.text(), language, function (html) {
$el.html(html);
});
});
},
onRequestResult: function onRequestResult(event) {

@ -2,6 +2,8 @@
```bash
$ gcc -xc - <<APP
```
```c
#include <stdio.h>
int main() {
int *p = NULL;
@ -10,6 +12,8 @@ int main() {
printf("After pointer dereference\n");
return 0;
}
```
```bash
APP
$ ./a.out
Before pointer dereference

@ -1,9 +1,11 @@
define(['jquery', 'lib/syntax'], function ($, syntax) {
describe('syntax', function () {
it('→ converts javascript to html', function () {
it('→ converts javascript to html', function (done) {
var src = 'function () {console.log("hi");}';
var actual = syntax(src);
expect($(actual).text()).toBe(src);
syntax(src, null, function (actual) {
expect($(actual).text()).toBe(src);
done();
});
});
});
});

Loading…
Cancel
Save