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

Function renderContentAsJSONMarkdown

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

renderContentAsJSONMarkdown tries to unmarshal the given content as JSON, wrap that content in a markdown JSON code block, and render it as markdown. If label is non-empty, it is rendered as leading text before and outside of the JSON block.

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

Source from the content-addressed store, hash-verified

273// If label is non-empty, it is rendered as leading text before and outside of
274// the JSON block.
275func renderContentAsJSONMarkdown(label, content string, w io.Writer, io *iostreams.IOStreams) error {
276 var contentAsJSON any
277 if err := json.Unmarshal([]byte(content), &contentAsJSON); err == nil {
278 marshaled, err := json.MarshalIndent(contentAsJSON, "", " ")
279 if err != nil {
280 return fmt.Errorf("failed to marshal JSON: %w", err)
281 }
282
283 if label != "" {
284 if err := renderRawMarkdown(label, w, io); err != nil {
285 return fmt.Errorf("failed to render label: %w", err)
286 }
287 }
288
289 if err := renderFileContentAsMarkdown("output.json", string(marshaled), w, io); err != nil {
290 return fmt.Errorf("failed to render JSON: %w", err)
291 }
292 }
293 return nil
294}
295
296// renderRawMarkdown renders the given raw markdown string to the given writer.
297// Use for complete markdown content from tool calls that need no conversion.

Callers 1

renderLogEntryFunction · 0.85

Calls 3

renderRawMarkdownFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected