Skip to content

Commit 5a34464

Browse files
matskomhevery
authored andcommitted
fix(ngdocs): fix gen_docs.sh
1 parent 5f92d41 commit 5a34464

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

docs/spec/domSpec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ describe('dom', function() {
2828
expect(dom.toString()).toContain('<h2>sub-heading</h2>');
2929
});
3030

31+
it('should properly number nested headings', function() {
32+
dom.h('heading', function() {
33+
dom.h('heading2', function() {
34+
this.html('<h1>heading3</h1>');
35+
});
36+
});
37+
dom.h('other1', function() {
38+
this.html('<h1>other2</h1>');
39+
});
40+
41+
expect(dom.toString()).toContain('<h1 id="heading">heading</h1>');
42+
expect(dom.toString()).toContain('<h2 id="heading2">heading2</h2>');
43+
expect(dom.toString()).toContain('<h3>heading3</h3>');
44+
45+
expect(dom.toString()).toContain('<h1 id="other1">other1</h1>');
46+
expect(dom.toString()).toContain('<h2>other2</h2>');
47+
});
48+
3149
});
3250

3351
});

docs/spec/ngdocSpec.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ describe('ngdoc', function() {
1818
describe('Doc', function() {
1919
describe('metadata', function() {
2020

21-
it('should find keywords', function() {
21+
it('should find keywords and filter ignored words', function() {
2222
expect(new Doc('\nHello: World! @ignore. $abc').keywords()).toEqual('$abc hello world');
23-
expect(new Doc('The `ng:class-odd` and').keywords()).toEqual('and ng:class-odd the');
23+
expect(new Doc('The `ng:class-odd` and').keywords()).toEqual('ng:class-odd');
2424
});
2525

2626
it('should get property and methods', function() {
@@ -147,7 +147,7 @@ describe('ngdoc', function() {
147147

148148
it('should replace text between two <pre></pre> tags', function() {
149149
expect(new Doc().markdown('<pre>x</pre>\n# One\n<pre>b</pre>')).
150-
toMatch('</pre>\n\n<h1>One</h1>\n\n<pre');
150+
toMatch('</pre>\n\n<h1 id="one">One</h1>\n\n<pre');
151151
});
152152

153153
it('should ignore nested doc widgets', function() {
@@ -405,7 +405,7 @@ describe('ngdoc', function() {
405405
expect(doc.description).
406406
toBe('<p>foo \n' +
407407
'<pre class="prettyprint linenums">abc</pre>\n\n' +
408-
'<h1>bah</h1>\n\n' +
408+
'<h1 id="bah">bah</h1>\n\n' +
409409
'<p>foo \n' +
410410
'<pre class="prettyprint linenums">cba</pre>');
411411

@@ -499,7 +499,7 @@ describe('ngdoc', function() {
499499
var doc = new Doc('@ngdoc overview\n@name angular\n@description\n#heading\ntext');
500500
doc.parse();
501501
expect(doc.html()).toContain('text');
502-
expect(doc.html()).toContain('<h2>heading</h2>');
502+
expect(doc.html()).toContain('<h2 id="heading">heading</h2>');
503503
expect(doc.html()).not.toContain('Description');
504504
});
505505
});
@@ -511,7 +511,7 @@ describe('ngdoc', function() {
511511
ngdoc:'function',
512512
name:'some.name',
513513
param: [
514-
{name:'a', optional: true},
514+
{name:'a', type: 'string', optional: true},
515515
{name:'b', type: 'someType', optional: true, 'default': '"xxx"'},
516516
{name:'c', type: 'string', description: 'param desc'}
517517
],
@@ -520,7 +520,7 @@ describe('ngdoc', function() {
520520
doc.html_usage_function(dom);
521521
expect(dom).toContain('name([a][, b], c)'); //TODO(i) the comma position here is lame
522522
expect(dom).toContain('param desc');
523-
expect(dom).toContain('(optional="xxx")');
523+
expect(dom).toContain('(optional)');
524524
expect(dom).toContain('return desc');
525525
});
526526
});
@@ -531,8 +531,8 @@ describe('ngdoc', function() {
531531
ngdoc:'formatter',
532532
shortName:'myFilter',
533533
param: [
534-
{name:'a'},
535-
{name:'b'}
534+
{name:'a', type:'string'},
535+
{name:'b', type:'string'}
536536
]
537537
});
538538
doc.html_usage_filter(dom);
@@ -546,6 +546,7 @@ describe('ngdoc', function() {
546546
var doc = new Doc({
547547
ngdoc:'property',
548548
name:'myProp',
549+
type:'string',
549550
returns:{type: 'type', description: 'description'}
550551
});
551552
doc.html_usage_property(dom);

docs/src/dom.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ DOM.prototype = {
4343
var headingDepth = this.headingDepth;
4444
for ( var i = 10; i > 0; --i) {
4545
html = html
46-
.replace(new RegExp('(<\/?h)' + i + '(>)', 'gm'), function(all, start, end){
47-
return start + (i + headingDepth) + end;
46+
.replace(new RegExp('<h' + i + '(.*?)>([\\s\\S]+)<\/h' + i +'>', 'gm'), function(_, attrs, content){
47+
var tag = 'h' + (i + headingDepth);
48+
return '<' + tag + attrs + '>' + content + '</' + tag + '>';
4849
});
4950
}
5051
this.out.push(html);

docs/src/ignore.words

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ without
678678
won't
679679
wont
680680
words
681-
world
682681
would
683682
wouldn't
684683
wouldnt

docs/src/ngdoc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var NEW_LINE = /\n\r?/;
1010
var globalID = 0;
1111
var fs = require('fs');
1212
var fspath = require('path');
13+
var markdown = new Showdown.converter({ extensions : ['table'] });
1314

1415
exports.trim = trim;
1516
exports.metadata = metadata;
@@ -216,7 +217,7 @@ Doc.prototype = {
216217
});
217218
});
218219
text = parts.join('');
219-
text = new Showdown.converter({ extensions : ['table'] }).makeHtml(text);
220+
text = markdown.makeHtml(text);
220221
text = text.replace(/(?:<p>)?(REPLACEME\d+)(?:<\/p>)?/g, function(_, id) {
221222
return placeholderMap[id];
222223
});

0 commit comments

Comments
 (0)