Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing of description after the @component #91

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/v3/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ class Parser extends EventEmitter {
emitGlobalComment(comment) {
if (comment && utils.isTopLevelComment(comment)) {
if (this.features.includes('description')) {
this.emit(ParserEvent.DESCRIPTION, comment.description);
const description = comment.description ||
comment.keywords.find(k => k.name === 'component').description;

this.emit(ParserEvent.DESCRIPTION, description);
}

if (this.features.includes('keywords')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script>
/** What should we call the user? */
export let name = 'world';
</script>

<!--
@component
Here's some documentation for this component.
It will show up on hover.

- You can use markdown here.
- You can also use code blocks here.
- Usage:
```tsx
<main name="Arethra">
```
-->
<main>
<h1>
Hello, {name}
</h1>
</main>

18 changes: 18 additions & 0 deletions test/svelte3/integration/globalComment/globalComment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ describe('SvelteDoc v3 - Global component', () => {
}).catch(done);
});

it('Global component data should be parsed with HTML comment (Official Example)', (done) => {
parser.parse({
version: 3,
filename: path.resolve(__dirname, 'globalComment.markup-off.svelte'),
features: ['description', 'keywords'],
includeSourceLocations: true,
ignoredVisibilities: []
}).then((doc) => {
expect(doc, 'Document should be provided').to.exist;
expect(doc.description, 'Document description should be parsed').to.exist;
expect(doc.keywords, 'Document keywords should be parsed').to.exist;

expect(doc.description, 'Document description text').to.contain("Here's some documentation for this component.");
expect(doc.keywords, 'Document keywords length').to.have.length(1);
done();
}).catch(done);
});

it('Global component data should be parsed with JS comment', (done) => {
parser.parse({
version: 3,
Expand Down