Show More
@@ -0,0 +1,36 b'' | |||||
|
1 | ||||
|
2 | // Test | |||
|
3 | casper.notebook_test(function () { | |||
|
4 | ||||
|
5 | var that = this; | |||
|
6 | var set_prompt = function (i, val) { | |||
|
7 | that.evaluate(function (i, val) { | |||
|
8 | var cell = IPython.notebook.get_cell(i); | |||
|
9 | cell.set_input_prompt(val); | |||
|
10 | }, [i, val]); | |||
|
11 | }; | |||
|
12 | ||||
|
13 | var get_prompt = function (i) { | |||
|
14 | return that.evaluate(function (i) { | |||
|
15 | var elem = IPython.notebook.get_cell(i).element; | |||
|
16 | return elem.find('div.input_prompt').html(); | |||
|
17 | }, [i]); | |||
|
18 | }; | |||
|
19 | ||||
|
20 | this.then(function () { | |||
|
21 | var a = 'print("a")'; | |||
|
22 | var index = this.append_cell(a); | |||
|
23 | ||||
|
24 | this.test.assertEquals(get_prompt(index), "In [ ]:", "prompt number is by default"); | |||
|
25 | set_prompt(index, 2); | |||
|
26 | this.test.assertEquals(get_prompt(index), "In [2]:", "prompt number is 2"); | |||
|
27 | set_prompt(index, 0); | |||
|
28 | this.test.assertEquals(get_prompt(index), "In [0]:", "prompt number is 0"); | |||
|
29 | set_prompt(index, "*"); | |||
|
30 | this.test.assertEquals(get_prompt(index), "In [*]:", "prompt number is *"); | |||
|
31 | set_prompt(index, undefined); | |||
|
32 | this.test.assertEquals(get_prompt(index), "In [ ]:", "prompt number is "); | |||
|
33 | set_prompt(index, null); | |||
|
34 | this.test.assertEquals(get_prompt(index), "In [ ]:", "prompt number is "); | |||
|
35 | }); | |||
|
36 | }); |
@@ -0,0 +1,81 b'' | |||||
|
1 | { | |||
|
2 | "metadata": { | |||
|
3 | "name": "notebook2" | |||
|
4 | }, | |||
|
5 | "nbformat": 3, | |||
|
6 | "nbformat_minor": 0, | |||
|
7 | "worksheets": [ | |||
|
8 | { | |||
|
9 | "cells": [ | |||
|
10 | { | |||
|
11 | "cell_type": "code", | |||
|
12 | "collapsed": false, | |||
|
13 | "input": [ | |||
|
14 | "import numpy as np" | |||
|
15 | ], | |||
|
16 | "language": "python", | |||
|
17 | "metadata": {}, | |||
|
18 | "outputs": [], | |||
|
19 | "prompt_number": 2 | |||
|
20 | }, | |||
|
21 | { | |||
|
22 | "cell_type": "code", | |||
|
23 | "collapsed": false, | |||
|
24 | "input": [ | |||
|
25 | "evs = np.zeros(100)", | |||
|
26 | "evs.shape" | |||
|
27 | ], | |||
|
28 | "language": "python", | |||
|
29 | "metadata": {}, | |||
|
30 | "outputs": [ | |||
|
31 | { | |||
|
32 | "metadata": {}, | |||
|
33 | "output_type": "pyout", | |||
|
34 | "prompt_number": 10, | |||
|
35 | "text": [ | |||
|
36 | "(100,)" | |||
|
37 | ] | |||
|
38 | } | |||
|
39 | ], | |||
|
40 | "prompt_number": 10 | |||
|
41 | }, | |||
|
42 | { | |||
|
43 | "cell_type": "code", | |||
|
44 | "collapsed": false, | |||
|
45 | "input": [], | |||
|
46 | "language": "python", | |||
|
47 | "metadata": {}, | |||
|
48 | "outputs": [] | |||
|
49 | }, | |||
|
50 | { | |||
|
51 | "cell_type": "code", | |||
|
52 | "collapsed": false, | |||
|
53 | "input": [], | |||
|
54 | "language": "python", | |||
|
55 | "metadata": {}, | |||
|
56 | "outputs": [], | |||
|
57 | "prompt_number": null | |||
|
58 | }, | |||
|
59 | { | |||
|
60 | "cell_type": "code", | |||
|
61 | "collapsed": false, | |||
|
62 | "input": [], | |||
|
63 | "language": "python", | |||
|
64 | "metadata": {}, | |||
|
65 | "outputs": [], | |||
|
66 | "prompt_number": "*" | |||
|
67 | }, | |||
|
68 | { | |||
|
69 | "cell_type": "code", | |||
|
70 | "collapsed": false, | |||
|
71 | "input": [], | |||
|
72 | "language": "python", | |||
|
73 | "metadata": {}, | |||
|
74 | "outputs": [], | |||
|
75 | "prompt_number": 0 | |||
|
76 | } | |||
|
77 | ], | |||
|
78 | "metadata": {} | |||
|
79 | } | |||
|
80 | ] | |||
|
81 | } No newline at end of file |
@@ -396,7 +396,7 b' var IPython = (function (IPython) {' | |||||
396 |
|
396 | |||
397 | CodeCell.input_prompt_classical = function (prompt_value, lines_number) { |
|
397 | CodeCell.input_prompt_classical = function (prompt_value, lines_number) { | |
398 | var ns; |
|
398 | var ns; | |
399 | if (prompt_value === undefined) { |
|
399 | if (prompt_value === undefined || prompt_value === null) { | |
400 | ns = " "; |
|
400 | ns = " "; | |
401 | } else { |
|
401 | } else { | |
402 | ns = encodeURIComponent(prompt_value); |
|
402 | ns = encodeURIComponent(prompt_value); |
@@ -15,6 +15,7 b'' | |||||
15 | from .base import ExportersTestsBase |
|
15 | from .base import ExportersTestsBase | |
16 | from ..html import HTMLExporter |
|
16 | from ..html import HTMLExporter | |
17 | from IPython.testing.decorators import onlyif_any_cmd_exists |
|
17 | from IPython.testing.decorators import onlyif_any_cmd_exists | |
|
18 | import re | |||
18 |
|
19 | |||
19 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- | |
20 | # Class |
|
21 | # Class | |
@@ -59,3 +60,18 b' class TestHTMLExporter(ExportersTestsBase):' | |||||
59 | (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook()) |
|
60 | (output, resources) = HTMLExporter(template_file='full').from_filename(self._get_notebook()) | |
60 | assert len(output) > 0 |
|
61 | assert len(output) > 0 | |
61 |
|
62 | |||
|
63 | @onlyif_any_cmd_exists('nodejs', 'node', 'pandoc') | |||
|
64 | def test_prompt_number(self): | |||
|
65 | """ | |||
|
66 | Does HTMLExporter properly format input and output prompts? | |||
|
67 | """ | |||
|
68 | (output, resources) = HTMLExporter(template_file='full').from_filename( | |||
|
69 | self._get_notebook(nb_name="prompt_numbers.ipynb")) | |||
|
70 | in_regex = r"In \[(.*)\]:" | |||
|
71 | out_regex = r"Out\[(.*)\]:" | |||
|
72 | ||||
|
73 | ins = ["2", "10", " ", " ", "*", "0"] | |||
|
74 | outs = ["10"] | |||
|
75 | ||||
|
76 | assert re.findall(in_regex, output) == ins | |||
|
77 | assert re.findall(out_regex, output) == outs |
@@ -23,7 +23,11 b'' | |||||
23 |
|
23 | |||
24 | {% block in_prompt -%} |
|
24 | {% block in_prompt -%} | |
25 | <div class="prompt input_prompt"> |
|
25 | <div class="prompt input_prompt"> | |
26 | In [{{ cell.prompt_number }}]: |
|
26 | {%- if cell.prompt_number is defined -%} | |
|
27 | In [{{ cell.prompt_number|replace(None, " ") }}]: | |||
|
28 | {%- else -%} | |||
|
29 | In [ ]: | |||
|
30 | {%- endif -%} | |||
27 | </div> |
|
31 | </div> | |
28 | {%- endblock in_prompt %} |
|
32 | {%- endblock in_prompt %} | |
29 |
|
33 | |||
@@ -51,7 +55,11 b' In [{{ cell.prompt_number }}]:' | |||||
51 | <div class="output_area"> |
|
55 | <div class="output_area"> | |
52 | {%- if output.output_type == 'pyout' -%} |
|
56 | {%- if output.output_type == 'pyout' -%} | |
53 | <div class="prompt output_prompt"> |
|
57 | <div class="prompt output_prompt"> | |
54 | Out[{{ cell.prompt_number }}]: |
|
58 | {%- if cell.prompt_number is defined -%} | |
|
59 | Out[{{ cell.prompt_number|replace(None, " ") }}]: | |||
|
60 | {%- else -%} | |||
|
61 | Out[ ]: | |||
|
62 | {%- endif -%} | |||
55 | {%- else -%} |
|
63 | {%- else -%} | |
56 | <div class="prompt"> |
|
64 | <div class="prompt"> | |
57 | {%- endif -%} |
|
65 | {%- endif -%} |
@@ -33,7 +33,11 b'' | |||||
33 | % Name: draw_prompt |
|
33 | % Name: draw_prompt | |
34 | % Purpose: Renders an output/input prompt |
|
34 | % Purpose: Renders an output/input prompt | |
35 | ((* macro add_prompt(text, cell, prompt) -*)) |
|
35 | ((* macro add_prompt(text, cell, prompt) -*)) | |
36 |
((*- |
|
36 | ((*- if cell.prompt_number is defined -*)) | |
|
37 | ((*- set prompt_number = "" ~ (cell.prompt_number | replace(None, " ")) -*)) | |||
|
38 | ((*- else -*)) | |||
|
39 | ((*- set prompt_number = " " -*)) | |||
|
40 | ((*- endif -*)) | |||
37 | ((*- set indentation = " " * (prompt_number | length + 7) -*)) |
|
41 | ((*- set indentation = " " * (prompt_number | length + 7) -*)) | |
38 | \begin{verbatim} |
|
42 | \begin{verbatim} | |
39 | (((- text | add_prompts(first=prompt ~ '[' ~ prompt_number ~ ']: ', cont=indentation) -))) |
|
43 | (((- text | add_prompts(first=prompt ~ '[' ~ prompt_number ~ ']: ', cont=indentation) -))) |
@@ -46,7 +46,11 b'' | |||||
46 | % Name: draw_prompt |
|
46 | % Name: draw_prompt | |
47 | % Purpose: Renders an output/input prompt |
|
47 | % Purpose: Renders an output/input prompt | |
48 | ((* macro add_prompt(text, cell, prompt, prompt_color) -*)) |
|
48 | ((* macro add_prompt(text, cell, prompt, prompt_color) -*)) | |
49 |
((*- |
|
49 | ((*- if cell.prompt_number is defined -*)) | |
|
50 | ((*- set prompt_number = "" ~ (cell.prompt_number | replace(None, " ")) -*)) | |||
|
51 | ((*- else -*)) | |||
|
52 | ((*- set prompt_number = " " -*)) | |||
|
53 | ((*- endif -*)) | |||
50 | ((*- set indention = " " * (prompt_number | length + 7) -*)) |
|
54 | ((*- set indention = " " * (prompt_number | length + 7) -*)) | |
51 | \begin{Verbatim}[commandchars=\\\{\}] |
|
55 | \begin{Verbatim}[commandchars=\\\{\}] | |
52 | ((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ prompt_number ~ '}]:} ', cont=indention) ))) |
|
56 | ((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ prompt_number ~ '}]:} ', cont=indention) ))) |
General Comments 0
You need to be logged in to leave comments.
Login now