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

feat: extend description extraction with Returns keyword #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions pkg/parser/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type DescriptionData struct {
Example string
Notes string
DeprecationNote string
Returns string

// Raw fields
DescriptionRaw string
Expand All @@ -71,34 +72,47 @@ func extractDescriptionData(doc string) DescriptionData {
var exampleLines []string
var notesLines []string
var deprecationNoteLines []string
var returnsLines []string

var description string
var example string
var notes string
var deprecationNote string
var returns string

isExample := false
isNotes := false
isDeprecationNote := false
isReturns := false

for _, line := range lines {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "Example:") {
isExample = true
isNotes = false
isDeprecationNote = false
isReturns = false
continue
}
if strings.HasPrefix(line, "Notes:") {
isNotes = true
isExample = false
isDeprecationNote = false
isReturns = false
continue
}
if strings.HasPrefix(line, "Deprecated:") {
isDeprecationNote = true
isExample = false
isNotes = false
isReturns = false
continue
}
if strings.HasPrefix(line, "Returns:") {
axtloss marked this conversation as resolved.
Show resolved Hide resolved
isReturns = true
isExample = false
isNotes = false
isDeprecationNote = false
continue
}

Expand All @@ -108,6 +122,8 @@ func extractDescriptionData(doc string) DescriptionData {
notesLines = append(notesLines, line)
} else if isDeprecationNote {
deprecationNoteLines = append(deprecationNoteLines, line)
} else if isReturns {
returnsLines = append(returnsLines, line)
} else {
descLines = append(descLines, line)
}
Expand Down Expand Up @@ -145,11 +161,20 @@ func extractDescriptionData(doc string) DescriptionData {
deprecationNote = ""
}

// Returns
returns = strings.Join(returnsLines, "</p>\n<p>")
returns = "<p>" + returns + "</p>"
returns = strings.ReplaceAll(returns, "\t", " ")
if returns == "<p></p>" {
returns = ""
}

return DescriptionData{
Description: description,
Example: example,
Notes: notes,
DeprecationNote: deprecationNote,
Returns: returns,

// Raw fields
DescriptionRaw: descriptionRaw,
Expand Down