MCPcopy Index your code
hub / github.com/cli/cli / renderFileContentAsMarkdown

Function renderFileContentAsMarkdown

pkg/cmd/agent-task/shared/log.go:367–382  ·  view source on GitHub ↗

renderFileContentAsMarkdown renders the given content as markdown based on the file extension of the path.

(path, content string, w io.Writer, io *iostreams.IOStreams)

Source from the content-addressed store, hash-verified

365// renderFileContentAsMarkdown renders the given content as markdown
366// based on the file extension of the path.
367func renderFileContentAsMarkdown(path, content string, w io.Writer, io *iostreams.IOStreams) error {
368 lang := filepath.Ext(filepath.ToSlash(path))
369
370 if lang == ".md" {
371 return renderRawMarkdown(content, w, io)
372 }
373
374 md := fmt.Sprintf("```%s\n%s\n```", lang, content)
375 // Glamour adds leading newlines when content is only a code block,
376 // so we only want to add a trailing newline.
377 formatFunc := func(s string) string {
378 return fmt.Sprintf("%s\n\n", s)
379 }
380
381 return renderMarkdownWithFormat(md, w, io, formatFunc)
382}
383
384// relativeFilePath converts an absolute file path to a relative one.
385// We expect paths to be of the form: /home/runner/work/<repo-owner>/<repo-name>/path/to/file

Callers 2

renderLogEntryFunction · 0.85

Calls 2

renderRawMarkdownFunction · 0.85
renderMarkdownWithFormatFunction · 0.85

Tested by

no test coverage detected