##// END OF EJS Templates
Merge pull request #10962 from sjdv1982/master...
Matthias Bussonnier -
r24123:8d769981 merge
parent child Browse files
Show More
@@ -1,70 +1,82 b''
1 1 """Simple magics for display formats"""
2 2 #-----------------------------------------------------------------------------
3 3 # Copyright (c) 2012 The IPython Development Team.
4 4 #
5 5 # Distributed under the terms of the Modified BSD License.
6 6 #
7 7 # The full license is in the file COPYING.txt, distributed with this software.
8 8 #-----------------------------------------------------------------------------
9 9
10 10 #-----------------------------------------------------------------------------
11 11 # Imports
12 12 #-----------------------------------------------------------------------------
13 13
14 14 # Our own packages
15 15 from IPython.core.display import display, Javascript, Latex, SVG, HTML, Markdown
16 16 from IPython.core.magic import (
17 17 Magics, magics_class, cell_magic
18 18 )
19 from IPython.core import magic_arguments
19 20
20 21 #-----------------------------------------------------------------------------
21 22 # Magic implementation classes
22 23 #-----------------------------------------------------------------------------
23 24
24 25
25 26 @magics_class
26 27 class DisplayMagics(Magics):
27 28 """Magics for displaying various output types with literals
28 29
29 30 Defines javascript/latex/svg/html cell magics for writing
30 31 blocks in those languages, to be rendered in the frontend.
31 32 """
32 33
33 34 @cell_magic
34 35 def js(self, line, cell):
35 36 """Run the cell block of Javascript code
36 37
37 38 Alias of `%%javascript`
38 39 """
39 40 self.javascript(line, cell)
40 41
41 42 @cell_magic
42 43 def javascript(self, line, cell):
43 44 """Run the cell block of Javascript code"""
44 45 display(Javascript(cell))
45 46
46 47
47 48 @cell_magic
48 49 def latex(self, line, cell):
49 50 """Render the cell as a block of latex
50 51
51 52 The subset of latex which is support depends on the implementation in
52 53 the client. In the Jupyter Notebook, this magic only renders the subset
53 54 of latex defined by MathJax
54 55 [here](https://docs.mathjax.org/en/v2.5-latest/tex.html)."""
55 56 display(Latex(cell))
56 57
57 58 @cell_magic
58 59 def svg(self, line, cell):
59 60 """Render the cell as an SVG literal"""
60 61 display(SVG(cell))
61 62
63 @magic_arguments.magic_arguments()
64 @magic_arguments.argument(
65 '--isolated', action='store_true', default=False,
66 help="""Annotate the cell as 'isolated'.
67 Isolated cells are rendered inside their own <iframe> tag"""
68 )
62 69 @cell_magic
63 70 def html(self, line, cell):
64 71 """Render the cell as a block of HTML"""
65 display(HTML(cell))
72 args = magic_arguments.parse_argstring(self.html, line)
73 html = HTML(cell)
74 if args.isolated:
75 display(html, metadata={'text/html':{'isolated':True}})
76 else:
77 display(html)
66 78
67 79 @cell_magic
68 80 def markdown(self, line, cell):
69 81 """Render the cell as Markdown text block"""
70 82 display(Markdown(cell))
General Comments 0
You need to be logged in to leave comments. Login now