Show More
@@ -11,9 +11,13 b' addition to the coalesce_streams pre-proccessor.' | |||||
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Functions |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
|
16 | import re | |||
16 |
|
17 | |||
|
18 | #----------------------------------------------------------------------------- | |||
|
19 | # Functions | |||
|
20 | #----------------------------------------------------------------------------- | |||
17 | def cell_preprocessor(function): |
|
21 | def cell_preprocessor(function): | |
18 | """ |
|
22 | """ | |
19 | Wrap a function to be executed on all cells of a notebook |
|
23 | Wrap a function to be executed on all cells of a notebook | |
@@ -66,21 +70,11 b' def coalesce_streams(cell, resources, index):' | |||||
66 | last.output_type == 'stream' and |
|
70 | last.output_type == 'stream' and | |
67 | last.stream == output.stream |
|
71 | last.stream == output.stream | |
68 | ): |
|
72 | ): | |
69 | # Either append this output to the existing or replace the last line |
|
73 | last.text += output.text | |
70 | # of the existing if a \r character is found. |
|
74 | ||
71 | if '\r' in output.text: |
|
75 | # Respect \r characters. | |
72 | existing_lines = last.text.split('\n') |
|
76 | cr_pat = re.compile(r'.*\r(?=[^\n])') | |
73 | new_pieces = output.text.split('\r') |
|
77 | last.text = cr_pat.sub('', last.text) | |
74 | # If there is any text preceding the first occurance of '\r', it |
|
|||
75 | # is appended as a new line to the lines. |
|
|||
76 | if len(new_pieces[0]) > 0: |
|
|||
77 | existing_lines.append(new_pieces[0]) |
|
|||
78 | # The text following the last occurance of '\r' replaces the |
|
|||
79 | # last line of text in the output. |
|
|||
80 | existing_lines[-1] = new_pieces[-1] |
|
|||
81 | last.text = '\n'.join(existing_lines) |
|
|||
82 | else: |
|
|||
83 | last.text += output.text |
|
|||
84 | else: |
|
78 | else: | |
85 | new_outputs.append(output) |
|
79 | new_outputs.append(output) | |
86 | last = output |
|
80 | last = output |
General Comments 0
You need to be logged in to leave comments.
Login now