This repository has been archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from taskcluster/worker-docs
Abstractions to let plugins and engines export end-user documentation
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package runtime | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
) | ||
|
||
// A Section represents a section of markdown documentation. | ||
type Section struct { | ||
Title string // Title of section rendered as headline level 2 | ||
Content string // Section contents, maybe contains headline level 3 and higher | ||
} | ||
|
||
// RenderDocument creates a markdown document with given title from a list of | ||
// sections. Ordering sections alphabetically. | ||
func RenderDocument(title string, sections []Section) string { | ||
sections = append([]Section{}, sections...) | ||
sort.Slice(sections, func(i int, j int) bool { | ||
return sections[i].Title < sections[j].Title | ||
}) | ||
|
||
docs := fmt.Sprintf("# %s\n", title) | ||
for _, section := range sections { | ||
docs += fmt.Sprintf("\n\n## %s\n%s\n", section.Title, section.Content) | ||
} | ||
return docs | ||
} |