Skip to content

Commit

Permalink
Merge 2b3ec76 into a544986
Browse files Browse the repository at this point in the history
  • Loading branch information
xi committed Apr 9, 2019
2 parents a544986 + 2b3ec76 commit 8edea39
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 83 deletions.
11 changes: 9 additions & 2 deletions src/annotation/annotations/group.js
Expand Up @@ -2,8 +2,15 @@ export default function group () {
return {
name: 'group',

parse (text) {
return [text.trim().toLowerCase()]
parse (text, info) {
let lines = text.trim().split('\n')
let slug = lines[0].trim().toLowerCase()
let description = lines.splice(1).join('\n').trim()
if (description) {
info.groupDescriptions = info.groupDescriptions || {}
info.groupDescriptions[slug] = description
}
return [slug]
},

default () {
Expand Down
21 changes: 21 additions & 0 deletions src/annotation/annotations/groupDescription.js
@@ -0,0 +1,21 @@
/**
* `@groupDescriptions` is should not be used on its own.
*
* It gets filled automatically from the lines following the `@group` annotation.
*
* @group example
* This is a group description. It describes the group.
* It can be split across multiple lines.
*
* {
* 'groupDescriptions': {
* 'example': 'This is a group description. It describes the group.\nIt can be split across multiple lines.'
* }
* }
*/

export default function groupDescriptions () {
return {
name: 'groupDescriptions',
}
}
1 change: 1 addition & 0 deletions src/annotation/annotations/index.js
Expand Up @@ -6,6 +6,7 @@ module.exports = [
require('./deprecated.js').default,
require('./example.js').default,
require('./group.js').default,
require('./groupDescription.js').default,
require('./ignore.js').default,
require('./link.js').default,
require('./name.js').default,
Expand Down
2 changes: 1 addition & 1 deletion test/annotations/api.test.js
Expand Up @@ -9,7 +9,7 @@ describe('#AnnotationsApi', function () {
it('should include the right number of annotations', function () {
assert.equal(
Object.keys(api.list).length,
21
22
)
})
})
8 changes: 8 additions & 0 deletions test/annotations/group.test.js
Expand Up @@ -10,4 +10,12 @@ describe('#group', function () {
assert.deepEqual(group.parse('group'), ['group'])
assert.deepEqual(group.parse('GRoup'), ['group'])
})

it('should parse a description from subsequent lines', function () {
var item = {}
assert.deepEqual(group.parse('group\ndescription', item), ['group'])
assert.deepEqual(item, {'groupDescriptions': {
'group': 'description'
}})
})
})

0 comments on commit 8edea39

Please sign in to comment.