Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ac6e130

Browse files
Di PengIgorMinar
Di Peng
authored andcommitted
fix(sample): Fix for jsFiddle integration
1 parent e004378 commit ac6e130

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

docs/spec/ngdocSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ describe('ngdoc', function(){
8989
'<pre class="doc-source">\n&lt;&gt;\n</pre></doc:example><p>after</p>');
9090
});
9191

92+
it('should preserve the jsfiddle attribute', function(){
93+
var doc = new Doc('@description before <doc:example>' +
94+
'<doc:source jsfiddle="foo">lala</doc:source></doc:example> after');
95+
doc.parse();
96+
expect(doc.description).toContain('<p>before </p><doc:example>' +
97+
'<pre class="doc-source" jsfiddle="foo">lala</pre></doc:example><p>after</p>');
98+
});
99+
92100
it('should escape <doc:scenario> element', function(){
93101
var doc = new Doc('@description before <doc:example>' +
94102
'<doc:scenario>\n<>\n</doc:scenario></doc:example> after');

docs/src/ngdoc.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ Doc.prototype = {
111111
'</pre></div>';
112112
});
113113
} else if (isDocWidget('example')) {
114-
text = text.replace(/(<doc:source>)([\s\S]*)(<\/doc:source>)/mi,
115-
function(_, before, content, after){
116-
return '<pre class="doc-source">' + htmlEscape(content) + '</pre>';
114+
text = text.replace(/<doc:source(\s+jsfiddle="[^"]+")?>([\s\S]*)<\/doc:source>/mi,
115+
function(_, jsfiddle, content){
116+
return '<pre class="doc-source"' + (jsfiddle || '') +'>' +
117+
htmlEscape(content) +
118+
'</pre>';
117119
});
118120
text = text.replace(/(<doc:scenario>)([\s\S]*)(<\/doc:scenario>)/mi,
119121
function(_, before, content, after){

docs/src/templates/doc_widgets.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//jqlite instead. jqlite's find() method currently supports onlt getElementsByTagName!
2929
var example = element.find('pre').eq(0), //doc-source
3030
exampleSrc = example.text(),
31-
jsfiddle = element.find('doc:source').attr('jsfiddle') || true,
31+
jsfiddle = example.attr('jsfiddle') || true,
3232
scenario = element.find('pre').eq(1); //doc-scenario
3333

3434
var code = indent(exampleSrc);

0 commit comments

Comments
 (0)