fix syntax highlighting on the javascript

This commit is contained in:
Misko Hevery 2011-04-29 14:43:43 -07:00 committed by Igor Minar
parent ea6b87c24b
commit b6bc6c2ddf
2 changed files with 10 additions and 5 deletions

View file

@ -307,10 +307,10 @@ describe('ngdoc', function(){
describe('@description', function(){
it('should support pre blocks', function(){
var doc = new Doc("@description <pre>abc</pre>");
var doc = new Doc("@description <pre><b>abc</b></pre>");
doc.parse();
expect(doc.description).
toBe('<div ng:non-bindable><pre class="brush: js; html-script: true;">abc</pre></div>');
toBe('<div ng:non-bindable><pre class="brush: js; html-script: true;">&lt;b&gt;abc&lt;/b&gt;</pre></div>');
});
it('should support multiple pre blocks', function() {
@ -318,10 +318,10 @@ describe('ngdoc', function(){
doc.parse();
expect(doc.description).
toBe('<p>foo </p>' +
'<div ng:non-bindable><pre class="brush: js; html-script: true;">abc</pre></div>' +
'<div ng:non-bindable><pre class="brush: js;">abc</pre></div>' +
'<h1>bah</h1>\n\n' +
'<p>foo </p>' +
'<div ng:non-bindable><pre class="brush: js; html-script: true;">cba</pre></div>');
'<div ng:non-bindable><pre class="brush: js;">cba</pre></div>');
});

View file

@ -70,7 +70,12 @@ Doc.prototype = {
parts.forEach(function(text, i){
if (text.match(/^<pre>/)) {
text = text.replace(/^<pre>([\s\S]*)<\/pre>/mi, function(_, content){
return '<div ng:non-bindable><pre class="brush: js; html-script: true;">' +
var clazz = 'brush: js;'
if (content.match(/\<\w/)) {
// we are HTML
clazz += ' html-script: true;';
}
return '<div ng:non-bindable><pre class="' + clazz +'">' +
content.replace(/</g, '&lt;').replace(/>/g, '&gt;') +
'</pre></div>';
});