Show More
@@ -63,6 +63,7 b' class Converter(object):' | |||
|
63 | 63 | user_preamble = None |
|
64 | 64 | output = unicode() |
|
65 | 65 | raw_as_verbatim = False |
|
66 | blank_symbol = " " | |
|
66 | 67 | |
|
67 | 68 | def __init__(self, infile): |
|
68 | 69 | self.infile = infile |
@@ -79,6 +80,10 b' class Converter(object):' | |||
|
79 | 80 | if os.path.isdir(self.files_dir) and not os.listdir(self.files_dir): |
|
80 | 81 | os.rmdir(self.files_dir) |
|
81 | 82 | |
|
83 | def _get_prompt_number(self, cell): | |
|
84 | return cell.prompt_number if hasattr(cell, 'prompt_number') \ | |
|
85 | else self.blank_symbol | |
|
86 | ||
|
82 | 87 | def dispatch(self, cell_type): |
|
83 | 88 | """return cell_type dependent render method, for example render_code |
|
84 | 89 | """ |
@@ -11,6 +11,7 b' import io' | |||
|
11 | 11 | |
|
12 | 12 | class ConverterHTML(Converter): |
|
13 | 13 | extension = 'html' |
|
14 | blank_symbol = ' ' | |
|
14 | 15 | |
|
15 | 16 | def in_tag(self, tag, src, attrs=None): |
|
16 | 17 | """Return a list of elements bracketed by the given tag""" |
@@ -29,8 +30,7 b' class ConverterHTML(Converter):' | |||
|
29 | 30 | |
|
30 | 31 | def _out_prompt(self, output): |
|
31 | 32 | if output.output_type == 'pyout': |
|
32 | n = output.prompt_number if output.prompt_number is not None else ' ' | |
|
33 | content = 'Out[%s]:' % n | |
|
33 | content = 'Out[%s]:' % self._get_prompt_number(output) | |
|
34 | 34 | else: |
|
35 | 35 | content = '' |
|
36 | 36 | return ['<div class="prompt output_prompt">%s</div>' % content] |
@@ -93,7 +93,7 b' class ConverterHTML(Converter):' | |||
|
93 | 93 | lines = ['<div class="cell border-box-sizing code_cell vbox">'] |
|
94 | 94 | |
|
95 | 95 | lines.append('<div class="input hbox">') |
|
96 | n = cell.prompt_number if getattr(cell, 'prompt_number', None) is not None else ' ' | |
|
96 | n = self._get_prompt_number(cell) | |
|
97 | 97 | lines.append('<div class="prompt input_prompt">In [%s]:</div>' % n) |
|
98 | 98 | lines.append('<div class="input_area box-flex1">') |
|
99 | 99 | lines.append(highlight(cell.input)) |
@@ -19,10 +19,11 b' class ConverterMarkdown(Converter):' | |||
|
19 | 19 | if not cell.input: |
|
20 | 20 | return [] |
|
21 | 21 | lines = [] |
|
22 | n = self._get_prompt_number(cell) | |
|
22 | 23 | if self.show_prompts and not self.inline_prompt: |
|
23 |
lines.extend(['*In[%s]:*' % |
|
|
24 | lines.extend(['*In[%s]:*' % n, '']) | |
|
24 | 25 | if self.show_prompts and self.inline_prompt: |
|
25 |
prompt = 'In[%s]: ' % |
|
|
26 | prompt = 'In[%s]: ' % n | |
|
26 | 27 | input_lines = cell.input.split('\n') |
|
27 | 28 | src = prompt + input_lines[0] + '\n' + indent('\n'.join(input_lines[1:]), nspaces=len(prompt)) |
|
28 | 29 | else: |
@@ -30,7 +31,7 b' class ConverterMarkdown(Converter):' | |||
|
30 | 31 | src = highlight(src) if self.highlight_source else indent(src) |
|
31 | 32 | lines.extend([src, '']) |
|
32 | 33 | if cell.outputs and self.show_prompts and not self.inline_prompt: |
|
33 |
lines.extend(['*Out[%s]:*' % |
|
|
34 | lines.extend(['*Out[%s]:*' % n, '']) | |
|
34 | 35 | for output in cell.outputs: |
|
35 | 36 | conv_fn = self.dispatch(output.output_type) |
|
36 | 37 | lines.extend(conv_fn(output)) |
@@ -52,7 +53,7 b' class ConverterMarkdown(Converter):' | |||
|
52 | 53 | lines = [] |
|
53 | 54 | |
|
54 | 55 | ## if 'text' in output: |
|
55 |
## lines.extend(['*Out[%s]:*' % |
|
|
56 | ## lines.extend(['*Out[%s]:*' % self._get_prompt_number(cell), '']) | |
|
56 | 57 | |
|
57 | 58 | # output is a dictionary like object with type as a key |
|
58 | 59 | if 'latex' in output: |
@@ -33,21 +33,17 b' class ConverterPy(Converter):' | |||
|
33 | 33 | return ['#{0} {1}'.format('#'*cell.level, cell.source), ''] |
|
34 | 34 | |
|
35 | 35 | def render_code(self, cell): |
|
36 | try: | |
|
37 | prompt_number = cell.prompt_number | |
|
38 | except AttributeError: | |
|
39 | prompt_number = " " | |
|
40 | ||
|
36 | n = self._get_prompt_number(cell) | |
|
41 | 37 | if not cell.input: |
|
42 | 38 | return [] |
|
43 | 39 | lines = [] |
|
44 | 40 | if self.show_prompts: |
|
45 |
lines.extend(['# In[%s]:' % |
|
|
41 | lines.extend(['# In[%s]:' % n]) | |
|
46 | 42 | src = cell.input |
|
47 | 43 | lines.extend([src, '']) |
|
48 | 44 | if self.show_output: |
|
49 | 45 | if cell.outputs : |
|
50 |
lines.extend(['# Out[%s]:' % |
|
|
46 | lines.extend(['# Out[%s]:' % n]) | |
|
51 | 47 | for output in cell.outputs: |
|
52 | 48 | conv_fn = self.dispatch(output.output_type) |
|
53 | 49 | lines.extend(conv_fn(output)) |
@@ -66,7 +62,7 b' class ConverterPy(Converter):' | |||
|
66 | 62 | lines = [] |
|
67 | 63 | |
|
68 | 64 | ## if 'text' in output: |
|
69 |
## lines.extend(['*Out[%s]:*' % |
|
|
65 | ## lines.extend(['*Out[%s]:*' % self._get_prompt_number(cell), '']) | |
|
70 | 66 | |
|
71 | 67 | # output is a dictionary like object with type as a key |
|
72 | 68 | if 'latex' in output: |
@@ -15,12 +15,7 b' class ConverterRST(Converter):' | |||
|
15 | 15 | if not cell.input: |
|
16 | 16 | return [] |
|
17 | 17 | |
|
18 | try: | |
|
19 | prompt_number = cell.prompt_number | |
|
20 | except AttributeError: | |
|
21 | prompt_number = " " | |
|
22 | ||
|
23 | lines = ['In[%s]:' % prompt_number, ''] | |
|
18 | lines = ['In[%s]:' % self._get_prompt_number(cell), ''] | |
|
24 | 19 | lines.extend(rst_directive('.. code:: python', cell.input)) |
|
25 | 20 | |
|
26 | 21 | for output in cell.outputs: |
@@ -40,7 +35,7 b' class ConverterRST(Converter):' | |||
|
40 | 35 | return [cell.source] |
|
41 | 36 | |
|
42 | 37 | def render_pyout(self, output): |
|
43 |
lines = ['Out[%s]:' % output |
|
|
38 | lines = ['Out[%s]:' % self._get_prompt_number(output), ''] | |
|
44 | 39 | |
|
45 | 40 | # output is a dictionary like object with type as a key |
|
46 | 41 | if 'latex' in output: |
General Comments 0
You need to be logged in to leave comments.
Login now