Add function description parsing
This commit is contained in:
@@ -30,6 +30,7 @@ func init() {
|
|||||||
type (
|
type (
|
||||||
Function struct {
|
Function struct {
|
||||||
Name string
|
Name string
|
||||||
|
Description string
|
||||||
Arguments []Parameter
|
Arguments []Parameter
|
||||||
Returns []Parameter
|
Returns []Parameter
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
---@diagnostic disable: missing-return, lowercase-global
|
---@diagnostic disable: missing-return, lowercase-global
|
||||||
|
|
||||||
{{range .Arguments -}}
|
{{range .Arguments -}}
|
||||||
---@param {{.Name}} {{.Type}} {{.Description}}
|
---@param {{.Name}} {{.Type}} {{.Description}}
|
||||||
{{end -}}
|
{{end -}}
|
||||||
{{range .Returns -}}
|
{{range .Returns -}}
|
||||||
---@return {{.Type}} {{.Name}} {{if .Description}}#{{.Description}}{{end}}
|
---@return {{.Type}} {{.Name}} {{if .Description}}#{{.Description}}{{end}}
|
||||||
{{end -}}
|
{{end -}}
|
||||||
|
{{if .Description}}---{{.Description}}{{end}}
|
||||||
function {{.Name}}({{range $index, $param := .Arguments}}{{if $index}}, {{end}}{{$param.Name}}{{end}}) end
|
function {{.Name}}({{range $index, $param := .Arguments}}{{if $index}}, {{end}}{{$param.Name}}{{end}}) end
|
@@ -38,6 +38,16 @@ func ParseDoc(html string) (Function, error) {
|
|||||||
return res, fmt.Errorf("failed parsing html: %v", err)
|
return res, fmt.Errorf("failed parsing html: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doc.Find("div.api-desc").Each(func(i int, s *goquery.Selection) {
|
||||||
|
log.Printf("Parsing description %s", s.Text())
|
||||||
|
desc := s.Text()
|
||||||
|
desc = strings.ReplaceAll(desc, "\n", " ")
|
||||||
|
desc = strings.ReplaceAll(desc, "\t", " ")
|
||||||
|
desc = strings.ReplaceAll(desc, " ", " ")
|
||||||
|
desc = strings.TrimSpace(desc)
|
||||||
|
res.Description = desc
|
||||||
|
})
|
||||||
|
|
||||||
isArgs := false
|
isArgs := false
|
||||||
isReturn := false
|
isReturn := false
|
||||||
doc.Find("div.api-listing > p, div.api-listing > ul").Each(func(i int, s *goquery.Selection) {
|
doc.Find("div.api-listing > p, div.api-listing > ul").Each(func(i int, s *goquery.Selection) {
|
||||||
|
Reference in New Issue
Block a user