@@ -16,7 +16,7 @@ import (
1616
1717// Support an interface similar - but not identical - to the IPython (canonical Jupyter kernel).
1818// See http://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.display
19- // for a good overview of the support types. Note: This is missing _repr_markdown_ and _repr_javascript_.
19+ // for a good overview of the support types.
2020
2121const (
2222 MIMETypeHTML = "text/html"
@@ -30,6 +30,67 @@ const (
3030 MIMETypeSVG = "image/svg+xml"
3131)
3232
33+ /**
34+ * general interface, allows libraries to fully control
35+ * how their data is displayed by gophernotes.
36+ * Supports multiple MIME formats.
37+ *
38+ * Note that Data is an alias:
39+ * type Data = struct { Data, Metadata, Transient map[string]interface{} }
40+ * thus libraries can implement Renderer without importing gophernotes
41+ */
42+ type Renderer = interface {
43+ Render () Data
44+ }
45+
46+ /**
47+ * simplified interface, allows libraries to control
48+ * how their data is displayed by gophernotes.
49+ * It only supports a single MIME format.
50+ *
51+ * Note that MIMEMap is an alias
52+ * type MIMEMap = map[string]interface{}
53+ * thus libraries can implement SimpleRenderer without importing gophernotes
54+ */
55+ type SimpleRenderer = interface {
56+ Render () MIMEMap
57+ }
58+
59+ /**
60+ * specialized interfaces, each is dedicated to a specific MIME type.
61+ *
62+ * They are type aliases to emphasize that method signatures
63+ * are the only important thing, not the interface names.
64+ * Thus libraries can implement them without importing gophernotes
65+ */
66+ type HTMLer = interface {
67+ HTML () string
68+ }
69+ type Javascripter = interface {
70+ JavaScript () string
71+ }
72+ type JPEGer = interface {
73+ JPEG () []byte
74+ }
75+ type JSONer = interface {
76+ JSON () map [string ]interface {}
77+ }
78+ type Latexer = interface {
79+ Latex () string
80+ }
81+ type Markdowner = interface {
82+ Markdown () string
83+ }
84+ type PNGer = interface {
85+ PNG () []byte
86+ }
87+ type PDFer = interface {
88+ PDF () []byte
89+ }
90+ type SVGer = interface {
91+ SVG () string
92+ }
93+
3394// injected as placeholder in the interpreter, it's then replaced at runtime
3495// by a closure that knows how to talk with Jupyter
3596func stubDisplay (Data ) error {
@@ -122,10 +183,6 @@ func HTML(html string) Data {
122183 return MakeData (MIMETypeHTML , html )
123184}
124185
125- func JSON (json map [string ]interface {}) Data {
126- return MakeData (MIMETypeJSON , json )
127- }
128-
129186func JavaScript (javascript string ) Data {
130187 return MakeData (MIMETypeJavaScript , javascript )
131188}
@@ -134,6 +191,10 @@ func JPEG(jpeg []byte) Data {
134191 return MakeData (MIMETypeJPEG , jpeg )
135192}
136193
194+ func JSON (json map [string ]interface {}) Data {
195+ return MakeData (MIMETypeJSON , json )
196+ }
197+
137198func Latex (latex string ) Data {
138199 return MakeData3 (MIMETypeLatex , latex , "$" + strings .Trim (latex , "$" )+ "$" )
139200}
0 commit comments