Finalizing fixes to MathJax enhancements

* Cell.prototype.typeset functionality restored
* MathJax configuration files back in .js, delayedStartup
* Renamed HUB to hub
* Removed vestigial comment
* Restored Markdown Cell placeholder render functionality
Aron Ahmadia 13 years ago
parent 5863b6fd7f
commit cf0254bc31

@ -50,8 +50,11 @@ var IPython = (function (IPython) {
});
};
// prototype typeset method does nothing, see TextCell typeset
Cell.prototype.typeset = function () {
if (window.MathJax){
var cell_math = this.element.get(0);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_math]);
}
};
Cell.prototype.select = function () {

@ -16,6 +16,18 @@ IPython.mathjaxutils = (function (IPython) {
var init = function () {
if (window.MathJax) {
// MathJax loaded
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEnvironments: true
},
displayAlign: 'left', // Change this to 'center' to center equations.
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}}
}
});
MathJax.Hub.Configured();
} else if (window.mathjax_url != "") {
// Don't have MathJax, but should. Show dialog.
var dialog = $('<div></div>')
@ -89,12 +101,12 @@ IPython.mathjaxutils = (function (IPython) {
// math, then push the math string onto the storage array.
// The preProcess function is called on all blocks if it has been passed in
var process_math = function (i, j, pre_process) {
var HUB = MathJax.Hub;
var hub = MathJax.Hub;
var block = blocks.slice(i, j + 1).join("").replace(/&/g, "&amp;") // use HTML entity for &
.replace(/</g, "&lt;") // use HTML entity for <
.replace(/>/g, "&gt;") // use HTML entity for >
;
if (HUB.Browser.isMSIE) {
if (hub.Browser.isMSIE) {
block = block.replace(/(%[^\n]*)\n/g, "$1<br/>\n")
}
while (j > i) {

@ -40,7 +40,6 @@ var IPython = (function (IPython) {
onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
});
// The tabindex=-1 makes this div focusable.
// id is a unique cell_id necessary for updating MathJax intelligently
var render_area = $('<div/>').addClass('text_cell_render border-box-sizing').
addClass('rendered_html').attr('tabindex','-1');
cell.append(input_area).append(render_area);
@ -78,13 +77,6 @@ var IPython = (function (IPython) {
return false;
};
TextCell.prototype.typeset = function () {
if (window.MathJax){
var cell_math = this.element.get(0);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_math]);
}
};
TextCell.prototype.select = function () {
IPython.Cell.prototype.select.apply(this);
@ -229,35 +221,33 @@ var IPython = (function (IPython) {
if (this.rendered === false) {
var text = this.get_text();
if (text === "") { text = this.placeholder; }
else {
text = IPython.mathjaxutils.remove_math(text)
var html = IPython.markdown_converter.makeHtml(text);
html = IPython.mathjaxutils.replace_math(html)
try {
this.set_rendered(html);
} catch (e) {
console.log("Error running Javascript in Markdown:");
console.log(e);
this.set_rendered($("<div/>").addClass("js-error").html(
"Error rendering Markdown!<br/>" + e.toString())
);
}
this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
var code_snippets = this.element.find("pre > code");
code_snippets.replaceWith(function () {
var code = $(this).html();
/* Substitute br for newlines and &nbsp; for spaces
before highlighting, since prettify doesn't
preserve those on all browsers */
code = code.replace(/(\r\n|\n|\r)/gm, "<br/>");
code = code.replace(/ /gm, '&nbsp;');
code = prettyPrintOne(code);
return '<code class="prettyprint">' + code + '</code>';
});
this.typeset()
text = IPython.mathjaxutils.remove_math(text)
var html = IPython.markdown_converter.makeHtml(text);
html = IPython.mathjaxutils.replace_math(html)
try {
this.set_rendered(html);
} catch (e) {
console.log("Error running Javascript in Markdown:");
console.log(e);
this.set_rendered($("<div/>").addClass("js-error").html(
"Error rendering Markdown!<br/>" + e.toString())
);
}
this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
var code_snippets = this.element.find("pre > code");
code_snippets.replaceWith(function () {
var code = $(this).html();
/* Substitute br for newlines and &nbsp; for spaces
before highlighting, since prettify doesn't
preserve those on all browsers */
code = code.replace(/(\r\n|\n|\r)/gm, "<br/>");
code = code.replace(/ /gm, '&nbsp;');
code = prettyPrintOne(code);
return '<code class="prettyprint">' + code + '</code>';
});
this.typeset()
this.rendered = true;
}
};

@ -2,21 +2,7 @@
{% block stylesheet %}
{% if mathjax_url %}
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEnvironments: true
},
displayAlign: 'left', // Change this to 'center' to center equations.
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}}
}
});
</script>
<script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML-full" charset="utf-8"></script>
<script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML-full&delayStartupUntil=configured" charset="utf-8"></script>
{% end %}
<script type="text/javascript">
// MathJax disabled, set as null to distingish from *missing* MathJax,

Loading…
Cancel
Save