renderFileContentAsMarkdown renders the given content as markdown based on the file extension of the path.
(path, content string, w io.Writer, io *iostreams.IOStreams)
| 365 | // renderFileContentAsMarkdown renders the given content as markdown |
| 366 | // based on the file extension of the path. |
| 367 | func 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 |
no test coverage detected