github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/cmd/gen-kismatic-ref-docs/markdownlong.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 type markdown struct{} 9 10 func (markdown) render(docs []doc) { 11 fmt.Println("# Plan File Reference") 12 fmt.Println("## Index") 13 for _, d := range docs { 14 props := strings.Split(d.property, ".") 15 spaces := strings.Repeat(" ", len(props)-1) 16 link := strings.Replace(d.property, ".", "", -1) 17 prop := props[len(props)-1] 18 if d.deprecated { 19 prop = prop + " _(deprecated)_" 20 link = link + "-deprecated" 21 } 22 fmt.Printf("%s* [%s](#%s)\n", spaces, prop, link) 23 } 24 25 for _, d := range docs { 26 propName := d.property 27 if d.deprecated { 28 propName = propName + " _(deprecated)_" 29 } 30 // Check if this is a top-level property 31 if !strings.Contains(propName, ".") { 32 fmt.Println("## ", propName) 33 } else { 34 fmt.Println("### ", propName) 35 } 36 37 fmt.Println() 38 fmt.Println(d.description) 39 fmt.Println() 40 if isStruct(d.propertyType) { 41 continue 42 } 43 fmt.Println("| | |") 44 fmt.Println("|----------|-----------------|") 45 fmt.Println("| **Kind** | ", d.propertyType, "|") 46 req := "No" 47 if d.required { 48 req = "Yes" 49 } 50 fmt.Println("| **Required** | ", req, "|") 51 def := d.defaultValue 52 if def == "" && d.propertyType == "bool" { 53 def = "false" 54 } 55 if def == "" { 56 def = " " 57 } 58 fmt.Printf("| **Default** | `%s` | \n", def) 59 if len(d.options) > 0 { 60 fmt.Println("| **Options** | ", strings.Join(wrapEach(d.options, "`"), ", ")) 61 } 62 fmt.Println() 63 } 64 } 65 66 func wrapEach(s []string, w string) []string { 67 res := make([]string, len(s)) 68 for i := 0; i < len(s); i++ { 69 res[i] = w + s[i] + w 70 } 71 return res 72 }