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