Skip to content

Commit

Permalink
Special case headings
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe committed Oct 10, 2022
1 parent 0097c72 commit 49dd8db
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/codegen/docs/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (dctx *docGenContext) decomposeDocstring(docstring string) docInfo {
Snippets: map[string]string{},
}
var nextTitle string
var nextInferredTitle string
// Push any examples we have found. Since `pushExamples` is called between sections,
// it needs to behave correctly when no examples were found.
pushExamples := func() {
Expand All @@ -72,11 +73,15 @@ func (dctx *docGenContext) decomposeDocstring(docstring string) docInfo {

examples = append(examples, currentSection)
}
if nextTitle == "" {
nextTitle = nextInferredTitle
}
currentSection = exampleSection{
Snippets: map[string]string{},
Title: nextTitle,
}
nextTitle = ""
nextInferredTitle = ""
}
err := ast.Walk(parsed, func(n ast.Node, enter bool) (ast.WalkStatus, error) {
// ast.Walk visits each node twice. The first time descending and the second time
Expand Down Expand Up @@ -119,6 +124,7 @@ func (dctx *docGenContext) decomposeDocstring(docstring string) docInfo {
nextTitle = title
}
}
return ast.WalkSkipChildren, nil

case *ast.FencedCodeBlock:
language := string(n.Language(source))
Expand All @@ -141,7 +147,7 @@ func (dctx *docGenContext) decomposeDocstring(docstring string) docInfo {
} else {
// Since we might find out we are done with the previous section only
// after we have consumed the next title, we store the title.
nextTitle = title
nextInferredTitle = title
}
}

Expand Down

0 comments on commit 49dd8db

Please sign in to comment.