github.com/dancsecs/gotomd@v0.0.0-20240310162206-65c4805cf510/doc_info.go (about) 1 /* 2 Golang To Github Markdown Utility: gotomd 3 Copyright (C) 2023, 2024 Leslie Dancsecs 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <https://www.gnu.org/licenses/>. 17 */ 18 19 package main 20 21 import ( 22 "strings" 23 ) 24 25 type docInfo struct { 26 header []string 27 body []string 28 doc []string 29 } 30 31 func (di *docInfo) oneLine() string { 32 res := "" 33 34 switch len(di.header) { 35 case 0: 36 switch len(di.body) { 37 case 0: 38 res = "UNKNOWN DECLARATION" 39 case 1: 40 res = di.body[0] 41 default: 42 res = di.body[0] + " ..." 43 } 44 case 1: 45 res = di.header[0] 46 default: 47 for _, l := range di.header { 48 if strings.HasSuffix(res, ",") { 49 res += " " 50 } 51 52 res += strings.TrimSpace(l) 53 } 54 55 res = strings.ReplaceAll(res, ", )", ")") 56 } 57 58 return res 59 } 60 61 func (di *docInfo) naturalComments() string { 62 res := "" 63 for _, l := range di.doc { 64 if res != "" { 65 res += "\n" 66 } 67 68 res += "// " + l 69 } 70 71 return res 72 } 73 74 func (di *docInfo) declGoLang() string { 75 return markGoCode(strings.Join(di.header, "\n")) 76 } 77 78 func (di *docInfo) docMarkdown() string { 79 return strings.Join(di.doc, "\n") 80 }