Show More
@@ -27,7 +27,7 b' var IPython = (function (IPython) {' | |||
|
27 | 27 | * |
|
28 | 28 | * @class TextCell |
|
29 | 29 | * @constructor TextCell |
|
30 |
* @extend I |
|
|
30 | * @extend IPython.Cell | |
|
31 | 31 | * @param {object|undefined} [options] |
|
32 | 32 | * @param [options.cm_config] {object} config to pass to CodeMirror, will extend/overwrite default config |
|
33 | 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 | 286 | * @class MarkdownCell |
|
287 | 287 | * @constructor MarkdownCell |
|
288 |
* @extends I |
|
|
288 | * @extends IPython.HTMLCell | |
|
289 | 289 | */ |
|
290 | 290 | var MarkdownCell = function (options) { |
|
291 | 291 | var options = options || {}; |
@@ -342,7 +342,7 b' var IPython = (function (IPython) {' | |||
|
342 | 342 | /** |
|
343 | 343 | * @class RawCell |
|
344 | 344 | * @constructor RawCell |
|
345 |
* @extends I |
|
|
345 | * @extends IPython.TextCell | |
|
346 | 346 | */ |
|
347 | 347 | var RawCell = function (options) { |
|
348 | 348 | |
@@ -437,12 +437,12 b' var IPython = (function (IPython) {' | |||
|
437 | 437 | |
|
438 | 438 | /** |
|
439 | 439 | * @class HeadingCell |
|
440 |
* @extends I |
|
|
440 | * @extends IPython.TextCell | |
|
441 | 441 | */ |
|
442 | 442 | |
|
443 | 443 | /** |
|
444 | 444 | * @constructor HeadingCell |
|
445 |
* @extends I |
|
|
445 | * @extends IPython.TextCell | |
|
446 | 446 | */ |
|
447 | 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 ( |
|
|
505 |
|
|
|
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 | ); | |
|
504 | HeadingCell.prototype.set_rendered = function (html) { | |
|
505 | this.element.find("div.text_cell_render").html(html); | |
|
522 | 506 | }; |
|
523 | 507 | |
|
524 | 508 | |
@@ -531,8 +515,24 b' var IPython = (function (IPython) {' | |||
|
531 | 515 | HeadingCell.prototype.render = function () { |
|
532 | 516 | if (this.rendered === false) { |
|
533 | 517 | var text = this.get_text(); |
|
518 | // Markdown headings must be a single line | |
|
519 | text = text.replace(/\n/g, ' '); | |
|
534 | 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 | 536 | this.typeset(); |
|
537 | 537 | this.element.find('div.text_cell_input').hide(); |
|
538 | 538 | this.element.find("div.text_cell_render").show(); |
@@ -19,11 +19,6 b' div.text_cell_render {' | |||
|
19 | 19 | color: @textColor; |
|
20 | 20 | } |
|
21 | 21 | |
|
22 | a.heading-anchor { | |
|
23 | text-decoration: none; | |
|
24 | color: inherit; | |
|
25 | } | |
|
26 | ||
|
27 | 22 | a.anchor-link:link { |
|
28 | 23 | text-decoration: none; |
|
29 | 24 | padding: 0px 20px; |
@@ -1559,7 +1559,6 b' span#checkpoint_status,span#autosave_status{font-size:small;}' | |||
|
1559 | 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 | 1560 | div.text_cell_input{color:#000000;border:1px solid #cfcfcf;border-radius:4px;background:#f7f7f7;} |
|
1561 | 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 | 1562 | a.anchor-link:link{text-decoration:none;padding:0px 20px;visibility:hidden;} |
|
1564 | 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 | 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 | 57 | 'rm_ansi': filters.remove_ansi, |
|
58 | 58 | 'rm_dollars': filters.strip_dollars, |
|
59 | 59 | 'rm_fake': filters.rm_fake, |
|
60 | 'html_text' : filters.html_text, | |
|
61 | 'add_anchor': filters.add_anchor, | |
|
60 | 62 | 'ansi2latex': filters.ansi2latex, |
|
61 | 63 | 'rm_math_space': filters.rm_math_space, |
|
62 | 64 | 'wrap': filters.wrap |
@@ -52,7 +52,7 b' def markdown2latex(source):' | |||
|
52 | 52 | |
|
53 | 53 | def markdown2html(source): |
|
54 | 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 | 57 | def markdown2rst(source): |
|
58 | 58 | """Convert a markdown string to LaTeX via pandoc. |
@@ -1,3 +1,4 b'' | |||
|
1 | # coding: utf-8 | |
|
1 | 2 | """String filters. |
|
2 | 3 | |
|
3 | 4 | Contains a collection of useful string manipulation filters for use in Jinja |
@@ -17,6 +18,9 b' templates.' | |||
|
17 | 18 | |
|
18 | 19 | import re |
|
19 | 20 | import textwrap |
|
21 | from xml.etree import ElementTree | |
|
22 | ||
|
23 | from IPython.utils import py3compat | |
|
20 | 24 | |
|
21 | 25 | #----------------------------------------------------------------------------- |
|
22 | 26 | # Functions |
@@ -24,6 +28,8 b' import textwrap' | |||
|
24 | 28 | |
|
25 | 29 | __all__ = [ |
|
26 | 30 | 'wrap', |
|
31 | 'html_text', | |
|
32 | 'add_anchor', | |
|
27 | 33 | 'strip_dollars', |
|
28 | 34 | 'rm_fake', |
|
29 | 35 | 'python_comment', |
@@ -50,6 +56,35 b' def wrap(text, width=100):' | |||
|
50 | 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 | 88 | def strip_dollars(text): |
|
54 | 89 | """ |
|
55 | 90 | Remove all dollar symbols from text |
@@ -59,12 +59,7 b' Out[{{cell.prompt_number}}]:' | |||
|
59 | 59 | |
|
60 | 60 | {% block headingcell scoped %} |
|
61 | 61 | <div class="text_cell_render border-box-sizing rendered_html"> |
|
62 | <h{{cell.level}}> | |
|
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}}> | |
|
62 | {{("#" * cell.level + cell.source) | replace('\n', ' ') | markdown | rm_fake | add_anchor }} | |
|
68 | 63 | </div> |
|
69 | 64 | {% endblock headingcell %} |
|
70 | 65 |
@@ -87,22 +87,7 b' it introduces a new line' | |||
|
87 | 87 | ((* endblock markdowncell *)) |
|
88 | 88 | |
|
89 | 89 | ((* block headingcell scoped -*)) |
|
90 | \ | |
|
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 )))} | |
|
90 | ((( ('#' * cell.level + cell.source) | replace('\n', ' ') | markdown2latex ))) | |
|
106 | 91 | ((* endblock headingcell *)) |
|
107 | 92 | |
|
108 | 93 | ((* block rawcell scoped *)) |
@@ -61,7 +61,7 b' $$' | |||
|
61 | 61 | |
|
62 | 62 | {% block headingcell scoped %} |
|
63 | 63 | |
|
64 | {{ '#' * cell.level }} {{ cell.source }} | |
|
64 | {{ '#' * cell.level }} {{ cell.source | replace('\n', ' ') }} | |
|
65 | 65 | |
|
66 | 66 | {% endblock headingcell %} |
|
67 | 67 |
@@ -44,7 +44,7 b' it introduces a new line' | |||
|
44 | 44 | {% endblock markdowncell %} |
|
45 | 45 | |
|
46 | 46 | {% block headingcell scoped %} |
|
47 | {{ '#' * cell.level }}{{ cell.source | pycomment}} | |
|
47 | {{ '#' * cell.level }}{{ cell.source | replace('\n', ' ') | pycomment}} | |
|
48 | 48 | {% endblock headingcell %} |
|
49 | 49 | |
|
50 | 50 | {% block rawcell scoped %} |
@@ -63,21 +63,7 b' Out[{{cell.prompt_number}}]:{% endif %}{% endblock output_prompt %}' | |||
|
63 | 63 | {% endblock markdowncell %} |
|
64 | 64 | |
|
65 | 65 | {% block headingcell scoped %} |
|
66 | {%- set len = cell.source|length -%} | |
|
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 %} | |
|
66 | {{ ("#" * cell.level + cell.source) | replace('\n', ' ') | markdown2rst }} | |
|
81 | 67 | |
|
82 | 68 | {% endblock headingcell %} |
|
83 | 69 |
@@ -24,7 +24,7 b' from IPython.utils.py3compat import cast_bytes' | |||
|
24 | 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 | 28 | """Convert an input string in format `from` to format `to` via pandoc. |
|
29 | 29 | |
|
30 | 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 | 44 | out : unicode |
|
45 | 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 | 51 | stdin=subprocess.PIPE, stdout=subprocess.PIPE |
|
49 | 52 | ) |
|
50 | 53 | out, _ = p.communicate(cast_bytes(source, encoding)) |
General Comments 0
You need to be logged in to leave comments.
Login now