{{- range $outputs }}
{{- $outputType := index . "output_type" | default "" -}}
{{- if eq $outputType "stream" }}
{{- $text := index . "text" -}}
{{- $textContent := "" -}}
{{- if reflect.IsSlice $text -}}
{{- $textContent = delimit $text "" -}}
{{- else if $text -}}
{{- $textContent = printf "%v" $text -}}
{{- end -}}
{{ $textContent | htmlEscape }}
{{- else if eq $outputType "error" }}
{{- $ename := index . "ename" | default "" -}}
{{- $evalue := index . "evalue" | default "" -}}
{{- $trace := index . "traceback" | default slice -}}
{{- $traceContent := "" -}}
{{- if reflect.IsSlice $trace -}}
{{- $traceContent = delimit $trace "\n" -}}
{{- else if $trace -}}
{{- $traceContent = printf "%v" $trace -}}
{{- end -}}
{{ printf "%s: %s" $ename $evalue }}
{{- if $traceContent }}
{{ $traceContent | htmlEscape }}
{{- end -}}
{{- else }}
{{- $data := index . "data" | default dict -}}
{{- $outputScratch := newScratch -}}
{{- $outputScratch.Set "rendered" false -}}
{{- with index $data "text/html" }}
{{- $htmlPayload := "" -}}
{{- if reflect.IsSlice . -}}
{{- $htmlPayload = delimit . "" -}}
{{- else -}}
{{- $htmlPayload = printf "%v" . -}}
{{- end -}}
{{- if $htmlPayload }}
{{ $htmlPayload | safeHTML }}
{{- $outputScratch.Set "rendered" true -}}
{{- end -}}
{{- end }}
{{- with index $data "text/markdown" }}
{{- $markdownPayload := "" -}}
{{- if reflect.IsSlice . -}}
{{- $markdownPayload = delimit . "" -}}
{{- else -}}
{{- $markdownPayload = printf "%v" . -}}
{{- end -}}
{{- if $markdownPayload }}
{{ $markdownPayload | markdownify }}
{{- $outputScratch.Set "rendered" true -}}
{{- end -}}
{{- end }}
{{- with index $data "text/latex" }}
{{- $latexPayload := "" -}}
{{- if reflect.IsSlice . -}}
{{- $latexPayload = delimit . "" -}}
{{- else -}}
{{- $latexPayload = printf "%v" . -}}
{{- end -}}
{{- if $latexPayload }}
{{ printf "$$%s$$" $latexPayload | safeHTML }}
{{- $outputScratch.Set "rendered" true -}}
{{- end -}}
{{- end }}
{{- with index $data "image/png" }}
{{- $pngPayload := printf "%v" . -}}
{{- if $pngPayload }}
{{- $outputScratch.Set "rendered" true -}}
{{- end -}}
{{- end }}
{{- with index $data "image/jpeg" }}
{{- $jpegPayload := printf "%v" . -}}
{{- if $jpegPayload }}
{{- $outputScratch.Set "rendered" true -}}
{{- end -}}
{{- end }}
{{- with index $data "image/svg+xml" }}
{{- $svgPayload := "" -}}
{{- if reflect.IsSlice . -}}
{{- $svgPayload = delimit . "" -}}
{{- else -}}
{{- $svgPayload = printf "%v" . -}}
{{- end -}}
{{- if $svgPayload }}
{{ $svgPayload | safeHTML }}
{{- $outputScratch.Set "rendered" true -}}
{{- end -}}
{{- end }}
{{- with or (index $data "application/vnd.plotly.v1+json") (index $data "application/json") }}
{{- $jsonFormatted := . | jsonify (dict "indent" " ") -}}
{{ $jsonFormatted }}
{{- $outputScratch.Set "rendered" true -}}
{{- end }}
{{- if not ($outputScratch.Get "rendered") }}
{{- with index $data "text/plain" }}
{{- $textPayload := "" -}}
{{- if reflect.IsSlice . -}}
{{- $textPayload = delimit . "" -}}
{{- else -}}
{{- $textPayload = printf "%v" . -}}
{{- end -}}
{{- if $textPayload }}
{{ $textPayload | htmlEscape }}
{{- $outputScratch.Set "rendered" true -}}
{{- end -}}
{{- end }}
{{- end }}
{{- if not ($outputScratch.Get "rendered") }}
{{ $data | jsonify | htmlEscape }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}