8000 Merge pull request #3364 from Carreau/requirejs · ipython/ipython@3db168c · GitHub
[go: up one dir, main page]

Skip to content

Commit 3db168c

Browse files
committed
Merge pull request #3364 from Carreau/requirejs
Inject requirejs in notebook and start using it. Mainly because the behavior of Marked change when require is injected. So only apply the modification needed for marked to behave.
2 parents ae8d945 + f2b674a commit 3db168c

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

IPython/frontend/html/notebook/static/notebook/js/main.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,27 @@
88
//============================================================================
99
// On document ready
1010
//============================================================================
11+
"use strict";
1112

13+
// for the time beeing, we have to pass marked as a parameter here,
14+
// as injecting require.js make marked not to put itself in the globals,
15+
// which make both this file fail at setting marked configuration, and textcell.js
16+
// which search marked into global.
17+
require(['components/marked/lib/marked'],
1218

13-
$(document).ready(function () {
19+
function (marked) {
20+
21+
window.marked = marked
1422

1523
// monkey patch CM to be able to syntax highlight cell magics
1624
// bug reported upstream,
1725
// see https://github.com/marijnh/CodeMirror2/issues/670
1826
if(CodeMirror.getMode(1,'text/plain').indent == undefined ){
1927
console.log('patching CM for undefined indent');
20-
CodeMirror.modes.null = function() { return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}}}
28+
CodeMirror.modes.null = function() {
29+
return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}}
2130
}
31+
}
2232

2333
CodeMirror.patchedGetMode = function(config, mode){
2434
var cmmode = CodeMirror.getMode(config, mode);
@@ -90,10 +100,10 @@ $(document).ready(function () {
90100
// only do this once
91101
$([IPython.events]).off('notebook_loaded.Notebook', first_load);
92102
};
93-
103+
94104
$([IPython.events]).on('notebook_loaded.Notebook', first_load);
95105
IPython.notebook.load_notebook($('body').data('notebookId'));
96-
106+
97107
if (marked) {
98108
marked.setOptions({
99109
gfm : true,
@@ -110,6 +120,6 @@ $(document).ready(function () {
110120
}
111121
})
112122
}
123+
}
113124

114-
});
115-
125+
);

IPython/frontend/html/notebook/templates/notebook.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@
206206
<script src="{{ static_url("components/codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script>
207207
<script src="{{ static_url("components/codemirror/mode/gfm/gfm.js") }}" charset="utf-8"></script>
208208

209-
<script src="{{ static_url("components/marked/lib/marked.js") }}" charset="utf-8"></script>
210209
<script src="{{ static_url("components/highlight.js/build/highlight.pack.js") }}" charset="utf-8"></script>
211210

212211
<script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script>

IPython/frontend/html/notebook/templates/page.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
{% endblock %}
2525
{% endblock %}
2626
<link rel="stylesheet" href="{{ static_url("custom/custom.css") }}" type="text/css" />
27-
27+
<script src="{{static_url("components/requirejs/require.js") }}" type="text/javascript" charset="utf-8"></script>
28+
<script>
29+
require.config({
30+
baseUrl: '{{static_url() }}',
31+
});
32+
</script>
2833

2934
{% block meta %}
3035
{% endblock %}

0 commit comments

Comments
 (0)
0