You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/Display.ipynb
+89Lines changed: 89 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -456,6 +456,95 @@
456
456
"func MakeData3(mimeType string, plaintext string, data interface{}) Data\n",
457
457
"func MIME(data, metadata MIMEMap) Data"
458
458
]
459
+
},
460
+
{
461
+
"cell_type": "markdown",
462
+
"metadata": {},
463
+
"source": [
464
+
"<h1 id=\"advanced\">Advanced usage</h1>\n",
465
+
"<p>gophernotes also provides the following interfaces, mainly targeted at authors of Go libraries.</p>\n",
466
+
"<p>If the only non-nil value returned at prompt has type <code>Data</code> or implements one of these interfaces, it will be automatically rendered graphically<p>\n",
467
+
"<p>Note: implementing these interface in interpreted code will not work as expected, because of the following known limitation of the underlying Go interpreter: if an interpreted type is converted to <code>interface{}</code>, it forgets all its methods - and gophernotes automatically converts to <code>interface{}</code> all values returned at prompt.<p>"
468
+
]
469
+
},
470
+
{
471
+
"cell_type": "code",
472
+
"execution_count": 2,
473
+
"metadata": {},
474
+
"outputs": [],
475
+
"source": [
476
+
"// MIMEMap holds data that can be presented in multiple formats. The keys are MIME types\n",
477
+
"// and the values are the data formatted with respect to its MIME type.\n",
478
+
"// All maps should contain at least a \"text/plain\" representation with a string value.\n",
479
+
"type MIMEMap = map[string]interface{}\n",
480
+
"\n",
481
+
"// Data is the exact structure returned to Jupyter.\n",
482
+
"// It allows to fully specify how a value should be displayed.\n",
483
+
"type Data = struct {\n",
484
+
"\tData MIMEMap\n",
485
+
"\tMetadata MIMEMap\n",
486
+
"\tTransient MIMEMap\n",
487
+
"}\n",
488
+
"\n",
489
+
"/**\n",
490
+
" * general interface, allows libraries to fully specify\n",
491
+
" * how their data is displayed by Jupyter.\n",
492
+
" * Supports multiple MIME formats.\n",
493
+
" *\n",
494
+
" * Note that Data defined above is an alias:\n",
495
+
" * libraries can implement Renderer without importing gophernotes\n",
496
+
" */\n",
497
+
"type Renderer = interface {\n",
498
+
"\tRender() Data\n",
499
+
"}\n",
500
+
"\n",
501
+
"/**\n",
502
+
" * simplified interface, allows libraries to specify\n",
503
+
" * how their data is displayed by Jupyter.\n",
504
+
" * It only supports a single MIME format.\n",
505
+
" *\n",
506
+
" * Note that MIMEMap defined above is an alias:\n",
507
+
" * libraries can implement SimpleRenderer without importing gophernotes\n",
508
+
" */\n",
509
+
"type SimpleRenderer = interface {\n",
510
+
"\tRender() MIMEMap\n",
511
+
"}\n",
512
+
"\n",
513
+
"/**\n",
514
+
" * specialized interfaces, each is dedicated to a specific MIME type.\n",
515
+
" *\n",
516
+
" * They are type aliases to emphasize that method signatures\n",
517
+
" * are the only important thing, not the interface names.\n",
518
+
" * Thus libraries can implement them without importing gophernotes\n",
0 commit comments