ngdoc should escape content of pre in markdown

This commit is contained in:
Igor Minar 2011-01-19 13:02:50 -08:00 committed by Misko Hevery
parent a5eb3ed107
commit 2c0f7ffe3a
2 changed files with 8 additions and 6 deletions

View file

@ -62,12 +62,12 @@ describe('ngdoc', function(){
toEqual('<p><tt>&lt;angular/&gt;</tt></p>');
});
it('should not replace anything in <pre>', function(){
expect(markdown('bah x\n<pre>\nangular.k\n</pre>\n asdf x')).
it('should not replace anything in <pre>, but escape the html escape the content', function(){
expect(markdown('bah x\n<pre>\n<b>angular</b>.k\n</pre>\n asdf x')).
toEqual(
'<p>bah x</p>' +
'<div ng:non-bindable><pre class="brush: js; html-script: true;">\n' +
'angular.k\n' +
'&lt;b&gt;angular&lt;/b&gt;.k\n' +
'</pre></div>' +
'<p>asdf x</p>');
});

View file

@ -421,9 +421,11 @@ function markdown (text) {
parts.forEach(function(text, i){
if (text.match(/^<pre>/)) {
text = text.
replace(/^<pre>/, '<div ng:non-bindable><pre class="brush: js; html-script: true;">').
replace(/<\/pre>/, '</pre></div>');
text = text.replace(/^<pre>([\s\S]*)<\/pre>/mi, function(_, content){
return '<div ng:non-bindable><pre class="brush: js; html-script: true;">' +
content.replace(/</g, '&lt;').replace(/>/g, '&gt;') +
'</pre></div>';
});
} else {
text = text.replace(/<angular\/>/gm, '<tt>&lt;angular/&gt;</tt>');
text = new Showdown.converter().makeHtml(text.replace(/^#/gm, '###'));