Show More
@@ -24,11 +24,11 b' class Notebook(Directive):' | |||||
24 | has_content = False |
|
24 | has_content = False | |
25 |
|
25 | |||
26 | def run(self): |
|
26 | def run(self): | |
27 | if (not self.state.document.settings.raw_enabled |
|
27 | # check if raw html is supported | |
28 |
|
|
28 | if not self.state.document.settings.raw_enabled: | |
29 | and ('file' in self.options |
|
|||
30 | or 'url' in self.options))): |
|
|||
31 | raise self.warning('"%s" directive disabled.' % self.name) |
|
29 | raise self.warning('"%s" directive disabled.' % self.name) | |
|
30 | ||||
|
31 | # set up encoding | |||
32 | attributes = {'format': 'html'} |
|
32 | attributes = {'format': 'html'} | |
33 | encoding = self.options.get( |
|
33 | encoding = self.options.get( | |
34 | 'encoding', self.state.document.settings.input_encoding) |
|
34 | 'encoding', self.state.document.settings.input_encoding) | |
@@ -37,35 +37,34 b' class Notebook(Directive):' | |||||
37 | # get path to notebook |
|
37 | # get path to notebook | |
38 | source_dir = os.path.dirname( |
|
38 | source_dir = os.path.dirname( | |
39 | os.path.abspath(self.state.document.current_source)) |
|
39 | os.path.abspath(self.state.document.current_source)) | |
40 | path = os.path.normpath(os.path.join(source_dir, |
|
40 | nb_path = os.path.normpath(os.path.join(source_dir, | |
41 | self.arguments[0])) |
|
41 | self.arguments[0])) | |
42 | path = utils.relative_path(None, path) |
|
42 | nb_path = utils.relative_path(None, nb_path) | |
43 |
|
43 | |||
44 | # convert notebook to html |
|
44 | # convert notebook to html | |
45 | converter = ConverterHTML(path) |
|
45 | converter = ConverterHTML(nb_path) | |
46 |
|
|
46 | converter.read() | |
47 | htmlpath = utils.relative_path(None, htmlfname) |
|
47 | ||
48 |
|
48 | # add HTML5 scoped attribute to header style tags | ||
49 | try: |
|
49 | header = map(lambda s: s.replace('<style', '<style scoped="scoped"'), | |
50 | raw_file = io.FileInput(source_path=htmlpath, |
|
50 | converter.header_body()) | |
51 | encoding=encoding, |
|
51 | ||
52 | error_handler=e_handler) |
|
52 | # concatenate raw html lines | |
53 | # TODO: currently, raw input files are recorded as |
|
53 | lines = ['<div class="ipynotebook">'] | |
54 | # dependencies even if not used for the chosen output format. |
|
54 | lines.extend(header) | |
55 | self.state.document.settings.record_dependencies.add(htmlpath) |
|
55 | lines.extend(converter.main_body()) | |
56 | except IOError, error: |
|
56 | lines.append('</div>') | |
57 | raise self.severe(u'Problems with "%s" directive path:\n%s.' |
|
57 | text = '\n'.join(lines) | |
58 | % (self.name, ErrorString(error))) |
|
|||
59 | try: |
|
|||
60 | text = raw_file.read() |
|
|||
61 | except UnicodeError, error: |
|
|||
62 | raise self.severe(u'Problem with "%s" directive:\n%s' |
|
|||
63 | % (self.name, ErrorString(error))) |
|
|||
64 | attributes['source'] = htmlpath |
|
|||
65 |
|
58 | |||
|
59 | # add dependency | |||
|
60 | self.state.document.settings.record_dependencies.add(nb_path) | |||
|
61 | attributes['source'] = nb_path | |||
|
62 | ||||
|
63 | # create notebook node | |||
66 | nb_node = notebook('', text, **attributes) |
|
64 | nb_node = notebook('', text, **attributes) | |
67 | (nb_node.source, |
|
65 | (nb_node.source, nb_node.line) = \ | |
68 |
|
|
66 | self.state_machine.get_source_and_line(self.lineno) | |
|
67 | ||||
69 | return [nb_node] |
|
68 | return [nb_node] | |
70 |
|
69 | |||
71 |
|
70 |
General Comments 0
You need to be logged in to leave comments.
Login now