MCPcopy
hub / github.com/gobyexample-cn/gobyexample / parseAndRenderSegs

Function parseAndRenderSegs

tools/generate.go:221–242  ·  view source on GitHub ↗
(sourcePath string)

Source from the content-addressed store, hash-verified

219}
220
221func parseAndRenderSegs(sourcePath string) ([]*Seg, string) {
222 segs, filecontent := parseSegs(sourcePath)
223 lexer := whichLexer(sourcePath)
224 for _, seg := range segs {
225 if seg.Docs != "" {
226 seg.DocsRendered = markdown(seg.Docs)
227 }
228 if seg.Code != "" {
229 seg.CodeRendered = chromaFormat(seg.Code, sourcePath)
230
231 // adding the content to the js code for copying to the clipboard
232 if strings.HasSuffix(sourcePath, ".go") {
233 seg.CodeForJs = strings.Trim(seg.Code, "\n") + "\n"
234 }
235 }
236 }
237 // we are only interested in the 'go' code to pass to play.golang.org
238 if lexer != "go" {
239 filecontent = ""
240 }
241 return segs, filecontent
242}
243
244func parseExamples() []*Example {
245 var exampleNames []string

Callers 1

parseExamplesFunction · 0.85

Calls 4

parseSegsFunction · 0.85
whichLexerFunction · 0.85
markdownFunction · 0.85
chromaFormatFunction · 0.85

Tested by

no test coverage detected