renderMarkdownWithFormat renders the given markdown string to the given writer. If a formatFunc is provided, the md string is ran through it before rendering. This can be used to add newlines before and after the content.
(md string, w io.Writer, io *iostreams.IOStreams, formatFunc func(string) string)
| 309 | // If a formatFunc is provided, the md string is ran through it before |
| 310 | // rendering. This can be used to add newlines before and after the content. |
| 311 | func renderMarkdownWithFormat(md string, w io.Writer, io *iostreams.IOStreams, formatFunc func(string) string) error { |
| 312 | rendered, err := markdown.Render(md, |
| 313 | markdown.WithTheme(io.TerminalTheme()), |
| 314 | markdown.WithWrap(io.TerminalWidth()), |
| 315 | ) |
| 316 | |
| 317 | if err != nil { |
| 318 | return fmt.Errorf("failed to render markdown: %w", err) |
| 319 | } |
| 320 | |
| 321 | rendered = strings.TrimSpace(rendered) |
| 322 | if formatFunc != nil { |
| 323 | rendered = formatFunc(rendered) |
| 324 | } |
| 325 | |
| 326 | fmt.Fprint(w, rendered) |
| 327 | |
| 328 | return nil |
| 329 | } |
| 330 | |
| 331 | // stripDiffFormat implements a primitive conversion from a diff string to a |
| 332 | // plain text representation by removing diff-specific formatting. |
no test coverage detected