##// END OF EJS Templates
cleanup implementation
Jake Vanderplas -
Show More
@@ -6,23 +6,17 b' from docutils import io, nodes, statemachine, utils'
6 from docutils.error_reporting import ErrorString
6 from docutils.error_reporting import ErrorString
7 from docutils.parsers.rst import Directive, convert_directive_function
7 from docutils.parsers.rst import Directive, convert_directive_function
8 from docutils.parsers.rst import directives, roles, states
8 from docutils.parsers.rst import directives, roles, states
9 from docutils.parsers.rst.directives.body import CodeBlock, NumberLines
10 from docutils.parsers.rst.roles import set_classes
9 from docutils.parsers.rst.roles import set_classes
11 from docutils.transforms import misc
10 from docutils.transforms import misc
12
11
13 from nbconvert import ConverterHTML
12 from nbconvert import ConverterHTML
14
13
15 class Notebook(Directive):
16
14
15 class Notebook(Directive):
17 """
16 """
18 Pass through content unchanged
17 Use nbconvert to insert a notebook into the environment.
19
18 This is based on the Raw directive in docutils
20 Content is included in output based on type argument
21
22 Content may be included inline (content section of directive) or
23 imported from a file or url.
24 """
19 """
25
26 required_arguments = 1
20 required_arguments = 1
27 optional_arguments = 0
21 optional_arguments = 0
28 final_argument_whitespace = True
22 final_argument_whitespace = True
@@ -50,7 +44,6 b' class Notebook(Directive):'
50 # convert notebook to html
44 # convert notebook to html
51 converter = ConverterHTML(path)
45 converter = ConverterHTML(path)
52 htmlfname = converter.render()
46 htmlfname = converter.render()
53
54 htmlpath = utils.relative_path(None, htmlfname)
47 htmlpath = utils.relative_path(None, htmlfname)
55
48
56 try:
49 try:
@@ -70,22 +63,24 b' class Notebook(Directive):'
70 % (self.name, ErrorString(error)))
63 % (self.name, ErrorString(error)))
71 attributes['source'] = htmlpath
64 attributes['source'] = htmlpath
72
65
66 nb_node = notebook('', text, **attributes)
67 (nb_node.source,
68 nb_node.line) = self.state_machine.get_source_and_line(self.lineno)
69 return [nb_node]
73
70
74
71
75 raw_node = nodes.raw('', text, **attributes)
72 class notebook(nodes.raw):
76 (raw_node.source,
77 raw_node.line) = self.state_machine.get_source_and_line(self.lineno)
78 return [raw_node]
79
80 class notebook(nodes.General, nodes.Element):
81 pass
73 pass
82
74
75
83 def visit_notebook_node(self, node):
76 def visit_notebook_node(self, node):
84 self.visit_raw(node)
77 self.visit_raw(node)
85
78
79
86 def depart_notebook_node(self, node):
80 def depart_notebook_node(self, node):
87 self.depart_raw(node)
81 self.depart_raw(node)
88
82
83
89 def setup(app):
84 def setup(app):
90 app.add_node(notebook,
85 app.add_node(notebook,
91 html=(visit_notebook_node, depart_notebook_node))
86 html=(visit_notebook_node, depart_notebook_node))
General Comments 0
You need to be logged in to leave comments. Login now