Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a1a7e1

Browse files
committed
fix(app): @example correct support
fix #1099
1 parent 18da1fe commit 9a1a7e1

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/utils/jsdoc-parser.util.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,26 @@ export class JsdocParserUtil {
9696

9797
const CODE_FENCE = /^\s*```(?!.*```)/;
9898
let inCode = false;
99-
function readLine(line: string) {
99+
let inExample = false; // first line with @example, end line with empty string or string or */
100+
let nbLines = 0;
101+
function readLine(line: string, index: number) {
100102
line = line.replace(/^\s*\*? ?/, '');
101103
line = line.replace(/\s*$/, '');
102104

103105
if (CODE_FENCE.test(line)) {
104106
inCode = !inCode;
105107
}
106108

109+
if (line.indexOf('@example') !== -1) {
110+
inExample = true;
111+
line = '```html';
112+
}
113+
114+
if (inExample && line === '') {
115+
inExample = false;
116+
line = '```';
117+
}
118+
107119
if (!inCode) {
108120
const tag = /^@(\S+)/.exec(line);
109121
const SeeTag = /^@see/.exec(line);
@@ -123,6 +135,8 @@ export class JsdocParserUtil {
123135
text = text.replace(/^\s*\/\*+/, '');
124136
text = text.replace(/\*+\/\s*$/, '');
125137

138+
nbLines = text.split(/\r\n?|\n/).length;
139+
126140
text.split(/\r\n?|\n/).forEach(readLine);
127141

128142
return comment;
@@ -272,8 +286,15 @@ export class JsdocParserUtil {
272286
case SyntaxKind.JSDocLink:
273287
if (JSDocNode.name) {
274288
let text = JSDocNode.name.escapedText;
275-
if (text === undefined && JSDocNode.name.left && JSDocNode.name.right) {
276-
text = JSDocNode.name.left.escapedText + '.' + JSDocNode.name.right.escapedText;
289+
if (
290+
text === undefined &&
291+
JSDocNode.name.left &&
292+
JSDocNode.name.right
293+
) {
294+
text =
295+
JSDocNode.name.left.escapedText +
296+
'.' +
297+
JSDocNode.name.right.escapedText;
277298
}
278299
rawDescription += JSDocNode.text + '{@link ' + text + '}';
279300
}

test/fixtures/todomvc-ng2/src/app/about/todomvc/todomvc.component.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Component } from '@angular/core';
22

33
/**
44
* The todomvc component
5+
*
6+
* @example
7+
* <todomvc>The example of the component</todomvc>
58
*/
69
@Component({
710
selector: 'todomvc',

test/src/cli/cli-generation-big-app.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('CLI simple generation - big app', () => {
1212
let searchFuncFile;
1313

1414
let todoComponentFile,
15+
todoMVCComponentFile,
1516
homeComponentFile,
1617
aboutComponentFile,
1718
appComponentFile,
@@ -50,6 +51,7 @@ describe('CLI simple generation - big app', () => {
5051

5152
routesIndex = read(`${distFolder}/js/routes/routes_index.js`);
5253
todoComponentFile = read(`${distFolder}/components/TodoComponent.html`);
54+
todoMVCComponentFile = read(`${distFolder}/components/TodoMVCComponent.html`);
5355
footerComponentFile = read(`${distFolder}/components/FooterComponent.html`);
5456
homeComponentFile = read(`${distFolder}/components/HomeComponent.html`);
5557
aboutComponentFile = read(`${distFolder}/components/AboutComponent.html`);
@@ -893,4 +895,10 @@ describe('CLI simple generation - big app', () => {
893895
'<a href="components/AppComponent.html" data-type="entity-link" >AppComponent</a>'
894896
);
895897
});
898+
899+
it('should support @example', () => {
900+
expect(todoMVCComponentFile).to.contain(
901+
'">&lt;todomvc&gt;The example of the component&lt;'
902+
);
903+
});
896904
});

0 commit comments

Comments
 (0)