Skip to content

Commit

Permalink
feat!: examples are now { name, content }
Browse files Browse the repository at this point in the history
Co-authored-by: Willow (GHOST) <ghostdevv@users.noreply.github.com>
  • Loading branch information
braebo and ghostdevv committed Dec 22, 2023
1 parent 7ed59d2 commit e3083a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-ears-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'extractinator': patch
---

breaking: examples are now `{ name, content }` instead of `string`
10 changes: 9 additions & 1 deletion src/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,15 @@ export function parseComment(commentString: string, parser: TSDocParser): TSDocC
switch (block.blockTag.tagName) {
case '@example':
found.examples ??= []
found.examples.push(render(block.content))
let content = render(block.content)

// If the first char is a space, remove it.
if (content.startsWith(' ')) {
content = content.slice(1)
}

const name = content.split('\n')?.[0]?.trim()
found.examples.push({ name, content: content.replace(name, '') })
break
case '@note':
found.notes ??= []
Expand Down
5 changes: 4 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ export interface TSDocComment extends Modifiers {
defaultValue?: string
returns?: string
notes?: string[]
examples?: string[]
examples?: {
name?: string
content: string
}[]
seeBlocks?: string[]
customBlocks?: { tagName: string; content: string }[]
/** The raw tsdoc comment. */
Expand Down

0 comments on commit e3083a8

Please sign in to comment.