1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
[ Div
( "0ad1fbe7-107b-4668-ae4d-8ce4ae9a4400"
, [ "cell" , "code" ]
, [ ( "execution_count" , "1" ) ]
)
[ CodeBlock
( "" , [ "python" ] , [] )
"from __future__ import annotations\n\nfrom dataclasses import dataclass"
]
, Div
( "c2d3a9f4-dfdb-4ced-bbcd-3dfd1780af80"
, [ "cell" , "code" ]
, [ ( "execution_count" , "2" ) ]
)
[ CodeBlock
( "" , [ "python" ] , [] )
"import IPython\n\nprint(IPython.__version__)"
, Div
( "" , [ "output" , "stream" , "stdout" ] , [] )
[ CodeBlock ( "" , [] , [] ) "7.29.0\n" ]
]
, Div
( "21e7a4a1-0cf8-48cc-823c-dca698ae6853"
, [ "cell" , "markdown" ]
, []
)
[ Para
[ Str "Supported"
, Space
, Str "IPython"
, Space
, Str "display"
, Space
, Str "formatters:"
]
]
, Div
( "053cdbc4-b157-4e3e-9c86-8f374770d006"
, [ "cell" , "code" ]
, [ ( "execution_count" , "3" ) ]
)
[ CodeBlock
( "" , [ "python" ] , [] )
"ip = get_ipython()\nfor mime in ip.display_formatter.formatters:\n print(mime)"
, Div
( "" , [ "output" , "stream" , "stdout" ] , [] )
[ CodeBlock
( "" , [] , [] )
"text/plain\ntext/html\ntext/markdown\nimage/svg+xml\nimage/png\napplication/pdf\nimage/jpeg\ntext/latex\napplication/json\napplication/javascript\n"
]
]
, Div
( "d79b063d-ce81-497b-a0ea-5b2e2972e845"
, [ "cell" , "markdown" ]
, []
)
[ Para
[ Str "Let's"
, Space
, Str "write"
, Space
, Str "a"
, Space
, Str "simple"
, Space
, Str "class"
, Space
, Str "that"
, Space
, Str "will"
, Space
, Str "output"
, Space
, Str "different"
, Space
, Str "mime:"
]
]
, Div
( "c847636c-1c45-432e-9d8d-7310dd7f5637"
, [ "cell" , "code" ]
, [ ( "execution_count" , "4" ) ]
)
[ CodeBlock
( "" , [ "python" ] , [] )
"@dataclass\nclass Mime:\n math: str\n\n def _repr_mimebundle_(\n self,\n include: Container[str] | None = None,\n exclude: Container[str] | None = None,\n **kwargs,\n ) -> dict[str, str]:\n string = self.math\n data = {\n \"text/plain\": string,\n \"text/html\": (latex := f\"\\\\[{string}\\\\]\"),\n \"text/markdown\": f\"$${string}$$\",\n # \"image/svg+xml\":,\n # \"image/png\":,\n # \"application/pdf\":,\n # \"image/jpeg\":,\n \"text/latex\": latex,\n # \"application/json\":,\n # \"application/javascript\":,\n }\n if include:\n data = {k: v for k, v in data.items() if k in include}\n if exclude:\n data = {k: v for k, v in data.items() if k not in exclude}\n return data"
]
, Div
( "4fa54f22-0c3a-4809-91f7-ea7101ff1907"
, [ "cell" , "code" ]
, [ ( "execution_count" , "5" ) ]
)
[ CodeBlock
( "" , [ "python" ] , [] ) "mime = Mime(\"E = mc^2\")"
]
, Div
( "c419e6a6-240c-4af0-a244-5f1526705c30"
, [ "cell" , "code" ]
, [ ( "execution_count" , "6" ) ]
)
[ CodeBlock ( "" , [ "python" ] , [] ) "mime"
, Div
( ""
, [ "output" , "execute_result" ]
, [ ( "execution_count" , "6" ) ]
)
[ RawBlock (Format "html") "\\[E = mc^2\\]"
, RawBlock (Format "latex") "\\[E = mc^2\\]"
, RawBlock (Format "markdown") "$$E = mc^2$$"
, CodeBlock ( "" , [] , [] ) "E = mc^2"
]
]
, Div
( "bf140b8e-16ac-4670-9778-f1c1d9486f9d"
, [ "cell" , "markdown" ]
, []
)
[ Para
[ Str "Note"
, Space
, Str "that"
, Space
, Str "#7561"
, Space
, Str "made"
, Space
, Str "ipynb"
, Space
, Str "reader"
, Space
, Str "aware"
, Space
, Str "of"
, Space
, Str "this,"
, Space
, Str "and"
, Space
, Str "#7563"
, Space
, Str "made"
, Space
, Str "ipynb"
, Space
, Str "writer"
, Space
, Str "aware"
, Space
, Str "of"
, Space
, Str "this."
]
]
]
|