Show More
@@ -27,7 +27,7 b' var IPython = (function (IPython) {' | |||||
27 | * |
|
27 | * | |
28 | * @class TextCell |
|
28 | * @class TextCell | |
29 | * @constructor TextCell |
|
29 | * @constructor TextCell | |
30 |
* @extend I |
|
30 | * @extend IPython.Cell | |
31 | * @param {object|undefined} [options] |
|
31 | * @param {object|undefined} [options] | |
32 | * @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config |
|
32 | * @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config | |
33 | * @param [options.placeholder] {string} default string to use when souce in empty for rendering (only use in some TextCell subclass) |
|
33 | * @param [options.placeholder] {string} default string to use when souce in empty for rendering (only use in some TextCell subclass) | |
@@ -285,7 +285,7 b' var IPython = (function (IPython) {' | |||||
285 | /** |
|
285 | /** | |
286 | * @class MarkdownCell |
|
286 | * @class MarkdownCell | |
287 | * @constructor MarkdownCell |
|
287 | * @constructor MarkdownCell | |
288 |
* @extends I |
|
288 | * @extends IPython.HTMLCell | |
289 | */ |
|
289 | */ | |
290 | var MarkdownCell = function (options) { |
|
290 | var MarkdownCell = function (options) { | |
291 | var options = options || {}; |
|
291 | var options = options || {}; | |
@@ -342,7 +342,7 b' var IPython = (function (IPython) {' | |||||
342 | /** |
|
342 | /** | |
343 | * @class RawCell |
|
343 | * @class RawCell | |
344 | * @constructor RawCell |
|
344 | * @constructor RawCell | |
345 |
* @extends I |
|
345 | * @extends IPython.TextCell | |
346 | */ |
|
346 | */ | |
347 | var RawCell = function (options) { |
|
347 | var RawCell = function (options) { | |
348 |
|
348 | |||
@@ -437,12 +437,12 b' var IPython = (function (IPython) {' | |||||
437 |
|
437 | |||
438 | /** |
|
438 | /** | |
439 | * @class HeadingCell |
|
439 | * @class HeadingCell | |
440 |
* @extends I |
|
440 | * @extends IPython.TextCell | |
441 | */ |
|
441 | */ | |
442 |
|
442 | |||
443 | /** |
|
443 | /** | |
444 | * @constructor HeadingCell |
|
444 | * @constructor HeadingCell | |
445 |
* @extends I |
|
445 | * @extends IPython.TextCell | |
446 | */ |
|
446 | */ | |
447 | var HeadingCell = function (options) { |
|
447 | var HeadingCell = function (options) { | |
448 |
|
448 | |||
@@ -501,24 +501,8 b' var IPython = (function (IPython) {' | |||||
501 | }; |
|
501 | }; | |
502 |
|
502 | |||
503 |
|
503 | |||
504 |
HeadingCell.prototype.set_rendered = function ( |
|
504 | HeadingCell.prototype.set_rendered = function (html) { | |
505 |
|
|
505 | this.element.find("div.text_cell_render").html(html); | |
506 | r.empty(); |
|
|||
507 | var link = text.replace(/ /g, '_'); |
|
|||
508 | r.append( |
|
|||
509 | $('<h'+this.level+'/>') |
|
|||
510 | .append( |
|
|||
511 | $('<a/>') |
|
|||
512 | .addClass('heading-anchor') |
|
|||
513 | .attr('id', link) |
|
|||
514 | .html(text) |
|
|||
515 | ).append( |
|
|||
516 | $('<a/>') |
|
|||
517 | .addClass('anchor-link') |
|
|||
518 | .attr('href', '#' + link) |
|
|||
519 | .text('¶') |
|
|||
520 | ) |
|
|||
521 | ); |
|
|||
522 | }; |
|
506 | }; | |
523 |
|
507 | |||
524 |
|
508 | |||
@@ -531,8 +515,24 b' var IPython = (function (IPython) {' | |||||
531 | HeadingCell.prototype.render = function () { |
|
515 | HeadingCell.prototype.render = function () { | |
532 | if (this.rendered === false) { |
|
516 | if (this.rendered === false) { | |
533 | var text = this.get_text(); |
|
517 | var text = this.get_text(); | |
|
518 | // Markdown headings must be a single line | |||
|
519 | text = text.replace(/\n/g, ' '); | |||
534 | if (text === "") { text = this.placeholder; } |
|
520 | if (text === "") { text = this.placeholder; } | |
535 | this.set_rendered(text); |
|
521 | text = Array(this.level + 1).join("#") + " " + text; | |
|
522 | text = IPython.mathjaxutils.remove_math(text); | |||
|
523 | var html = marked.parser(marked.lexer(text)); | |||
|
524 | var h = $(IPython.mathjaxutils.replace_math(html)); | |||
|
525 | // add id and linkback anchor | |||
|
526 | var hash = h.text().replace(/ /g, '-'); | |||
|
527 | h.attr('id', hash); | |||
|
528 | h.append( | |||
|
529 | $('<a/>') | |||
|
530 | .addClass('anchor-link') | |||
|
531 | .attr('href', '#' + hash) | |||
|
532 | .text('¶') | |||
|
533 | ); | |||
|
534 | ||||
|
535 | this.set_rendered(h); | |||
536 | this.typeset(); |
|
536 | this.typeset(); | |
537 | this.element.find('div.text_cell_input').hide(); |
|
537 | this.element.find('div.text_cell_input').hide(); | |
538 | this.element.find("div.text_cell_render").show(); |
|
538 | this.element.find("div.text_cell_render").show(); |
@@ -19,11 +19,6 b' div.text_cell_render {' | |||||
19 | color: @textColor; |
|
19 | color: @textColor; | |
20 | } |
|
20 | } | |
21 |
|
21 | |||
22 | a.heading-anchor { |
|
|||
23 | text-decoration: none; |
|
|||
24 | color: inherit; |
|
|||
25 | } |
|
|||
26 |
|
||||
27 | a.anchor-link:link { |
|
22 | a.anchor-link:link { | |
28 | text-decoration: none; |
|
23 | text-decoration: none; | |
29 | padding: 0px 20px; |
|
24 | padding: 0px 20px; |
@@ -1559,7 +1559,6 b' span#checkpoint_status,span#autosave_status{font-size:small;}' | |||||
1559 | @media (max-width:767px){span#save_widget{font-size:small;} span#checkpoint_status,span#autosave_status{font-size:x-small;}}@media (max-width:767px){span#checkpoint_status,span#autosave_status{display:none;}}@media (min-width:768px) and (max-width:979px){span#checkpoint_status{display:none;} span#autosave_status{font-size:x-small;}}div.text_cell{padding:5px 5px 5px 5px;} |
|
1559 | @media (max-width:767px){span#save_widget{font-size:small;} span#checkpoint_status,span#autosave_status{font-size:x-small;}}@media (max-width:767px){span#checkpoint_status,span#autosave_status{display:none;}}@media (min-width:768px) and (max-width:979px){span#checkpoint_status{display:none;} span#autosave_status{font-size:x-small;}}div.text_cell{padding:5px 5px 5px 5px;} | |
1560 | div.text_cell_input{color:#000000;border:1px solid #cfcfcf;border-radius:4px;background:#f7f7f7;} |
|
1560 | div.text_cell_input{color:#000000;border:1px solid #cfcfcf;border-radius:4px;background:#f7f7f7;} | |
1561 | div.text_cell_render{outline:none;resize:none;width:inherit;border-style:none;padding:5px;color:#000000;} |
|
1561 | div.text_cell_render{outline:none;resize:none;width:inherit;border-style:none;padding:5px;color:#000000;} | |
1562 | a.heading-anchor{text-decoration:none;color:inherit;} |
|
|||
1563 | a.anchor-link:link{text-decoration:none;padding:0px 20px;visibility:hidden;} |
|
1562 | a.anchor-link:link{text-decoration:none;padding:0px 20px;visibility:hidden;} | |
1564 | h1:hover .anchor-link,h2:hover .anchor-link,h3:hover .anchor-link,h4:hover .anchor-link,h5:hover .anchor-link,h6:hover .anchor-link{visibility:visible;} |
|
1563 | h1:hover .anchor-link,h2:hover .anchor-link,h3:hover .anchor-link,h4:hover .anchor-link,h5:hover .anchor-link,h6:hover .anchor-link{visibility:visible;} | |
1565 | .toolbar{padding:0px 10px;margin-top:-5px;}.toolbar select,.toolbar label{width:auto;height:26px;vertical-align:middle;margin-right:2px;margin-bottom:0px;display:inline;font-size:92%;margin-left:0.3em;margin-right:0.3em;padding:0px;padding-top:3px;} |
|
1564 | .toolbar{padding:0px 10px;margin-top:-5px;}.toolbar select,.toolbar label{width:auto;height:26px;vertical-align:middle;margin-right:2px;margin-bottom:0px;display:inline;font-size:92%;margin-left:0.3em;margin-right:0.3em;padding:0px;padding-top:3px;} |
@@ -57,6 +57,8 b' default_filters = {' | |||||
57 | 'rm_ansi': filters.remove_ansi, |
|
57 | 'rm_ansi': filters.remove_ansi, | |
58 | 'rm_dollars': filters.strip_dollars, |
|
58 | 'rm_dollars': filters.strip_dollars, | |
59 | 'rm_fake': filters.rm_fake, |
|
59 | 'rm_fake': filters.rm_fake, | |
|
60 | 'html_text' : filters.html_text, | |||
|
61 | 'add_anchor': filters.add_anchor, | |||
60 | 'ansi2latex': filters.ansi2latex, |
|
62 | 'ansi2latex': filters.ansi2latex, | |
61 | 'rm_math_space': filters.rm_math_space, |
|
63 | 'rm_math_space': filters.rm_math_space, | |
62 | 'wrap': filters.wrap |
|
64 | 'wrap': filters.wrap |
@@ -52,7 +52,7 b' def markdown2latex(source):' | |||||
52 |
|
52 | |||
53 | def markdown2html(source): |
|
53 | def markdown2html(source): | |
54 | """Convert a markdown string to HTML via pandoc""" |
|
54 | """Convert a markdown string to HTML via pandoc""" | |
55 | return pandoc(source, 'markdown', 'html') |
|
55 | return pandoc(source, 'markdown', 'html', extra_args=['--mathjax']) | |
56 |
|
56 | |||
57 | def markdown2rst(source): |
|
57 | def markdown2rst(source): | |
58 | """Convert a markdown string to LaTeX via pandoc. |
|
58 | """Convert a markdown string to LaTeX via pandoc. |
@@ -1,3 +1,4 b'' | |||||
|
1 | # coding: utf-8 | |||
1 | """String filters. |
|
2 | """String filters. | |
2 |
|
3 | |||
3 | Contains a collection of useful string manipulation filters for use in Jinja |
|
4 | Contains a collection of useful string manipulation filters for use in Jinja | |
@@ -17,6 +18,9 b' templates.' | |||||
17 |
|
18 | |||
18 | import re |
|
19 | import re | |
19 | import textwrap |
|
20 | import textwrap | |
|
21 | from xml.etree import ElementTree | |||
|
22 | ||||
|
23 | from IPython.utils import py3compat | |||
20 |
|
24 | |||
21 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
22 | # Functions |
|
26 | # Functions | |
@@ -24,6 +28,8 b' import textwrap' | |||||
24 |
|
28 | |||
25 | __all__ = [ |
|
29 | __all__ = [ | |
26 | 'wrap', |
|
30 | 'wrap', | |
|
31 | 'html_text', | |||
|
32 | 'add_anchor', | |||
27 | 'strip_dollars', |
|
33 | 'strip_dollars', | |
28 | 'rm_fake', |
|
34 | 'rm_fake', | |
29 | 'python_comment', |
|
35 | 'python_comment', | |
@@ -50,6 +56,35 b' def wrap(text, width=100):' | |||||
50 | return '\n'.join(wrpd) |
|
56 | return '\n'.join(wrpd) | |
51 |
|
57 | |||
52 |
|
58 | |||
|
59 | def html_text(element): | |||
|
60 | """extract inner text from html | |||
|
61 | ||||
|
62 | Analog of jQuery's $(element).text() | |||
|
63 | """ | |||
|
64 | if not isinstance(element, (ElementTree.ElementTree, ElementTree.Element)): | |||
|
65 | element = ElementTree.fromstring(element) | |||
|
66 | ||||
|
67 | text = element.text or "" | |||
|
68 | for child in element: | |||
|
69 | text += html_text(child) | |||
|
70 | text += (element.tail or "") | |||
|
71 | return text | |||
|
72 | ||||
|
73 | ||||
|
74 | def add_anchor(html): | |||
|
75 | """Add an anchor-link to an html header tag | |||
|
76 | ||||
|
77 | For use in heading cells | |||
|
78 | """ | |||
|
79 | h = ElementTree.fromstring(py3compat.cast_bytes_py2(html)) | |||
|
80 | link = html_text(h).replace(' ', '-') | |||
|
81 | h.set('id', link) | |||
|
82 | a = ElementTree.Element("a", {"class" : "anchor-link", "href" : "#" + link}) | |||
|
83 | a.text = u'¶' | |||
|
84 | h.append(a) | |||
|
85 | return ElementTree.tostring(h) | |||
|
86 | ||||
|
87 | ||||
53 | def strip_dollars(text): |
|
88 | def strip_dollars(text): | |
54 | """ |
|
89 | """ | |
55 | Remove all dollar symbols from text |
|
90 | Remove all dollar symbols from text |
@@ -59,12 +59,7 b' Out[{{cell.prompt_number}}]:' | |||||
59 |
|
59 | |||
60 | {% block headingcell scoped %} |
|
60 | {% block headingcell scoped %} | |
61 | <div class="text_cell_render border-box-sizing rendered_html"> |
|
61 | <div class="text_cell_render border-box-sizing rendered_html"> | |
62 | <h{{cell.level}}> |
|
62 | {{("#" * cell.level + cell.source) | replace('\n', ' ') | markdown | rm_fake | add_anchor }} | |
63 | {% set source = cell.source | replace(' ','_') %} |
|
|||
64 | <a class="heading-anchor" id="{{source}}" href="#{{source}}"> |
|
|||
65 | {{cell.source | markdown| rm_fake}} |
|
|||
66 | </a> |
|
|||
67 | </h{{cell.level}}> |
|
|||
68 | </div> |
|
63 | </div> | |
69 | {% endblock headingcell %} |
|
64 | {% endblock headingcell %} | |
70 |
|
65 |
@@ -87,22 +87,7 b' it introduces a new line' | |||||
87 | ((* endblock markdowncell *)) |
|
87 | ((* endblock markdowncell *)) | |
88 |
|
88 | |||
89 | ((* block headingcell scoped -*)) |
|
89 | ((* block headingcell scoped -*)) | |
90 | \ |
|
90 | ((( ('#' * cell.level + cell.source) | replace('\n', ' ') | markdown2latex ))) | |
91 | ((*- if cell.level == 1 -*)) |
|
|||
92 | ((* block h1 -*))section((* endblock h1 -*)) |
|
|||
93 | ((*- elif cell.level == 2 -*)) |
|
|||
94 | ((* block h2 -*))subsection((* endblock h2 -*)) |
|
|||
95 | ((*- elif cell.level == 3 -*)) |
|
|||
96 | ((* block h3 -*))subsubsection((* endblock h3 -*)) |
|
|||
97 | ((*- elif cell.level == 4 -*)) |
|
|||
98 | ((* block h4 -*))paragraph((* endblock h4 -*)) |
|
|||
99 | ((*- elif cell.level == 5 -*)) |
|
|||
100 | ((* block h5 -*))subparagraph((* endblock h5 -*)) |
|
|||
101 | ((*- elif cell.level == 6 -*)) |
|
|||
102 | ((* block h6 -*))subparagraph((* endblock h6 -*)) |
|
|||
103 | ((= 6th level not available in standard latex =)) |
|
|||
104 |
|
||||
105 | ((*- endif -*)){((( cell.source | markdown2latex )))} |
|
|||
106 | ((* endblock headingcell *)) |
|
91 | ((* endblock headingcell *)) | |
107 |
|
92 | |||
108 | ((* block rawcell scoped *)) |
|
93 | ((* block rawcell scoped *)) |
@@ -61,7 +61,7 b' $$' | |||||
61 |
|
61 | |||
62 | {% block headingcell scoped %} |
|
62 | {% block headingcell scoped %} | |
63 |
|
63 | |||
64 | {{ '#' * cell.level }} {{ cell.source }} |
|
64 | {{ '#' * cell.level }} {{ cell.source | replace('\n', ' ') }} | |
65 |
|
65 | |||
66 | {% endblock headingcell %} |
|
66 | {% endblock headingcell %} | |
67 |
|
67 |
@@ -44,7 +44,7 b' it introduces a new line' | |||||
44 | {% endblock markdowncell %} |
|
44 | {% endblock markdowncell %} | |
45 |
|
45 | |||
46 | {% block headingcell scoped %} |
|
46 | {% block headingcell scoped %} | |
47 | {{ '#' * cell.level }}{{ cell.source | pycomment}} |
|
47 | {{ '#' * cell.level }}{{ cell.source | replace('\n', ' ') | pycomment}} | |
48 | {% endblock headingcell %} |
|
48 | {% endblock headingcell %} | |
49 |
|
49 | |||
50 | {% block rawcell scoped %} |
|
50 | {% block rawcell scoped %} |
@@ -63,21 +63,7 b' Out[{{cell.prompt_number}}]:{% endif %}{% endblock output_prompt %}' | |||||
63 | {% endblock markdowncell %} |
|
63 | {% endblock markdowncell %} | |
64 |
|
64 | |||
65 | {% block headingcell scoped %} |
|
65 | {% block headingcell scoped %} | |
66 | {%- set len = cell.source|length -%} |
|
66 | {{ ("#" * cell.level + cell.source) | replace('\n', ' ') | markdown2rst }} | |
67 | {{ cell.source | markdown2rst }} |
|
|||
68 | {% if cell.level == 1 %} |
|
|||
69 | {{- '=' * len }} |
|
|||
70 | {%- elif cell.level == 2 %} |
|
|||
71 | {{- '-' * len }} |
|
|||
72 | {%- elif cell.level == 3 %} |
|
|||
73 | {{- '~' * len }} |
|
|||
74 | {%- elif cell.level == 4 %} |
|
|||
75 | {{- '.' * len }} |
|
|||
76 | {%- elif cell.level == 5 %} |
|
|||
77 | {{- '\\' * len }} |
|
|||
78 | {%- elif cell.level == 6 %} |
|
|||
79 | {{- '`' * len }} |
|
|||
80 | {% endif %} |
|
|||
81 |
|
67 | |||
82 | {% endblock headingcell %} |
|
68 | {% endblock headingcell %} | |
83 |
|
69 |
@@ -24,7 +24,7 b' from IPython.utils.py3compat import cast_bytes' | |||||
24 | # Classes and functions |
|
24 | # Classes and functions | |
25 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
26 |
|
26 | |||
27 | def pandoc(source, fmt, to, encoding='utf-8'): |
|
27 | def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'): | |
28 | """Convert an input string in format `from` to format `to` via pandoc. |
|
28 | """Convert an input string in format `from` to format `to` via pandoc. | |
29 |
|
29 | |||
30 | This function will raise an error if pandoc is not installed. |
|
30 | This function will raise an error if pandoc is not installed. | |
@@ -44,7 +44,10 b" def pandoc(source, fmt, to, encoding='utf-8'):" | |||||
44 | out : unicode |
|
44 | out : unicode | |
45 | Output as returned by pandoc. |
|
45 | Output as returned by pandoc. | |
46 | """ |
|
46 | """ | |
47 |
|
|
47 | command = ['pandoc', '-f', fmt, '-t', to] | |
|
48 | if extra_args: | |||
|
49 | command.extend(extra_args) | |||
|
50 | p = subprocess.Popen(command, | |||
48 | stdin=subprocess.PIPE, stdout=subprocess.PIPE |
|
51 | stdin=subprocess.PIPE, stdout=subprocess.PIPE | |
49 | ) |
|
52 | ) | |
50 | out, _ = p.communicate(cast_bytes(source, encoding)) |
|
53 | out, _ = p.communicate(cast_bytes(source, encoding)) |
General Comments 0
You need to be logged in to leave comments.
Login now