f996705 ←9555332antonApr 18, 2026 api

create mixed-outputs.ipynb via macOS

A /docs/undefined +155 -0
A /docs/undefined +155 -0
1{
2 "nbformat": 4,
3 "nbformat_minor": 5,
4 "metadata": {
5 "kernelspec": {
6 "display_name": "Python 3",
7 "language": "python",
8 "name": "python3"
9 },
10 "language_info": {
11 "name": "python",
12 "version": "3.12.0"
13 }
14 },
15 "cells": [
16 {
17 "cell_type": "markdown",
18 "metadata": {},
19 "source": [
20 "# Mixed Output Types\n",
21 "\n",
22 "Testing all output types: text, HTML, images (base64), SVG, and errors."
23 ]
24 },
25 {
26 "cell_type": "code",
27 "metadata": {},
28 "execution_count": 1,
29 "source": [
30 "# stream output — multiple prints\n",
31 "for i in range(5):\n",
32 " print(f\"Step {i + 1}: processing...\")\n",
33 "print(\"Done!\")"
34 ],
35 "outputs": [
36 {
37 "output_type": "stream",
38 "name": "stdout",
39 "text": [
40 "Step 1: processing...\n",
41 "Step 2: processing...\n",
42 "Step 3: processing...\n",
43 "Step 4: processing...\n",
44 "Step 5: processing...\n",
45 "Done!\n"
46 ]
47 }
48 ]
49 },
50 {
51 "cell_type": "markdown",
52 "metadata": {},
53 "source": [
54 "## SVG Output\n",
55 "\n",
56 "Inline SVG rendering (like matplotlib with SVG backend):"
57 ]
58 },
59 {
60 "cell_type": "code",
61 "metadata": {},
62 "execution_count": 2,
63 "source": [
64 "from IPython.display import SVG, display\n",
65 "\n",
66 "svg = '''<svg width=\"300\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\">\n",
67 " <rect x=\"10\" y=\"10\" width=\"80\" height=\"180\" fill=\"#4CAF50\" rx=\"4\"/>\n",
68 " <rect x=\"110\" y=\"60\" width=\"80\" height=\"130\" fill=\"#2196F3\" rx=\"4\"/>\n",
69 " <rect x=\"210\" y=\"100\" width=\"80\" height=\"90\" fill=\"#FF9800\" rx=\"4\"/>\n",
70 " <text x=\"50\" y=\"205\" text-anchor=\"middle\" font-size=\"12\">A</text>\n",
71 " <text x=\"150\" y=\"205\" text-anchor=\"middle\" font-size=\"12\">B</text>\n",
72 " <text x=\"250\" y=\"205\" text-anchor=\"middle\" font-size=\"12\">C</text>\n",
73 "</svg>'''\n",
74 "display(SVG(svg))"
75 ],
76 "outputs": [
77 {
78 "output_type": "display_data",
79 "data": {
80 "image/svg+xml": "<svg width=\"300\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\">\n <rect x=\"10\" y=\"10\" width=\"80\" height=\"180\" fill=\"#4CAF50\" rx=\"4\"/>\n <rect x=\"110\" y=\"60\" width=\"80\" height=\"130\" fill=\"#2196F3\" rx=\"4\"/>\n <rect x=\"210\" y=\"100\" width=\"80\" height=\"90\" fill=\"#FF9800\" rx=\"4\"/>\n <text x=\"50\" y=\"205\" text-anchor=\"middle\" font-size=\"12\">A</text>\n <text x=\"150\" y=\"205\" text-anchor=\"middle\" font-size=\"12\">B</text>\n <text x=\"250\" y=\"205\" text-anchor=\"middle\" font-size=\"12\">C</text>\n</svg>",
81 "text/plain": "<IPython.core.display.SVG object>"
82 },
83 "metadata": {}
84 }
85 ]
86 },
87 {
88 "cell_type": "markdown",
89 "metadata": {},
90 "source": [
91 "## Rich HTML Output\n",
92 "\n",
93 "Custom HTML via `display(HTML(...))`:"
94 ]
95 },
96 {
97 "cell_type": "code",
98 "metadata": {},
99 "execution_count": 3,
100 "source": [
101 "from IPython.display import HTML\n",
102 "\n",
103 "HTML('''\n",
104 "<div style=\"padding: 16px; border: 1px solid #ddd; border-radius: 8px; max-width: 400px;\">\n",
105 " <h3 style=\"margin: 0 0 8px 0;\">System Status</h3>\n",
106 " <table style=\"width: 100%; border-collapse: collapse;\">\n",
107 " <tr><td>CPU</td><td style=\"text-align: right; color: green;\">12%</td></tr>\n",
108 " <tr><td>Memory</td><td style=\"text-align: right; color: orange;\">67%</td></tr>\n",
109 " <tr><td>Disk</td><td style=\"text-align: right; color: green;\">34%</td></tr>\n",
110 " <tr><td>Network</td><td style=\"text-align: right; color: green;\">2.4 Mbps</td></tr>\n",
111 " </table>\n",
112 "</div>\n",
113 "''')"
114 ],
115 "outputs": [
116 {
117 "output_type": "execute_result",
118 "execution_count": 3,
119 "data": {
120 "text/html": "\n<div style=\"padding: 16px; border: 1px solid #ddd; border-radius: 8px; max-width: 400px;\">\n <h3 style=\"margin: 0 0 8px 0;\">System Status</h3>\n <table style=\"width: 100%; border-collapse: collapse;\">\n <tr><td>CPU</td><td style=\"text-align: right; color: green;\">12%</td></tr>\n <tr><td>Memory</td><td style=\"text-align: right; color: orange;\">67%</td></tr>\n <tr><td>Disk</td><td style=\"text-align: right; color: green;\">34%</td></tr>\n <tr><td>Network</td><td style=\"text-align: right; color: green;\">2.4 Mbps</td></tr>\n </table>\n</div>\n",
121 "text/plain": "<IPython.core.display.HTML object>"
122 },
123 "metadata": {}
124 }
125 ]
126 },
127 {
128 "cell_type": "markdown",
129 "metadata": {},
130 "source": [
131 "## Empty Cell\n",
132 "\n",
133 "An unexecuted code cell:"
134 ]
135 },
136 {
137 "cell_type": "code",
138 "metadata": {},
139 "execution_count": null,
140 "source": [
141 "# TODO: implement this later"
142 ],
143 "outputs": []
144 },
145 {
146 "cell_type": "raw",
147 "metadata": {},
148 "source": [
149 "This is a raw cell.\n",
150 "It is rendered as plain text without any formatting.\n",
151 "Useful for LaTeX or other markup that shouldn't be processed."
152 ]
153 }
154 ]
155}