Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50654 views
1
//----------------------------------------------------------------------------
2
// Copyright (C) 2011 The IPython Development Team
3
//
4
// Distributed under the terms of the BSD License. The full license is in
5
// the file COPYING, distributed as part of this software.
6
//----------------------------------------------------------------------------
7
8
//============================================================================
9
// On document ready
10
//============================================================================
11
12
// for the time beeing, we have to pass marked as a parameter here,
13
// as injecting require.js make marked not to put itself in the globals,
14
// which make both this file fail at setting marked configuration, and textcell.js
15
// which search marked into global.
16
require(['components/marked/lib/marked',
17
'widgets/js/init',
18
'components/bootstrap-tour/build/js/bootstrap-tour.min'],
19
20
function (marked) {
21
"use strict";
22
23
window.marked = marked;
24
25
// monkey patch CM to be able to syntax highlight cell magics
26
// bug reported upstream,
27
// see https://github.com/marijnh/CodeMirror2/issues/670
28
if(CodeMirror.getMode(1,'text/plain').indent === undefined ){
29
console.log('patching CM for undefined indent');
30
CodeMirror.modes.null = function() {
31
return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0;}};
32
};
33
}
34
35
CodeMirror.patchedGetMode = function(config, mode){
36
var cmmode = CodeMirror.getMode(config, mode);
37
if(cmmode.indent === null) {
38
console.log('patch mode "' , mode, '" on the fly');
39
cmmode.indent = function(){return 0;};
40
}
41
return cmmode;
42
};
43
// end monkey patching CodeMirror
44
45
IPython.mathjaxutils.init();
46
47
$('#ipython-main-app').addClass('border-box-sizing');
48
$('div#notebook_panel').addClass('border-box-sizing');
49
50
var opts = {
51
base_url : IPython.utils.get_body_data("baseUrl"),
52
notebook_path : IPython.utils.get_body_data("notebookPath"),
53
notebook_name : IPython.utils.get_body_data('notebookName')
54
};
55
56
IPython.page = new IPython.Page();
57
IPython.layout_manager = new IPython.LayoutManager();
58
IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
59
IPython.quick_help = new IPython.QuickHelp();
60
try {
61
IPython.tour = new IPython.NotebookTour();
62
} catch (e) {
63
console.log("Failed to instantiate Notebook Tour", e);
64
}
65
IPython.login_widget = new IPython.LoginWidget('span#login_widget', opts);
66
IPython.notebook = new IPython.Notebook('div#notebook', opts);
67
IPython.keyboard_manager = new IPython.KeyboardManager();
68
IPython.save_widget = new IPython.SaveWidget('span#save_widget');
69
IPython.menubar = new IPython.MenuBar('#menubar', opts);
70
IPython.toolbar = new IPython.MainToolBar('#maintoolbar-container');
71
IPython.tooltip = new IPython.Tooltip();
72
IPython.notification_area = new IPython.NotificationArea('#notification_area');
73
IPython.notification_area.init_notification_widgets();
74
75
IPython.layout_manager.do_resize();
76
77
$('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+
78
'<span id="test2" style="font-weight: bold;">x</span>'+
79
'<span id="test3" style="font-style: italic;">x</span></pre></div>');
80
var nh = $('#test1').innerHeight();
81
var bh = $('#test2').innerHeight();
82
var ih = $('#test3').innerHeight();
83
if(nh != bh || nh != ih) {
84
$('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>');
85
}
86
$('#fonttest').remove();
87
88
IPython.page.show();
89
90
IPython.layout_manager.do_resize();
91
var first_load = function () {
92
IPython.layout_manager.do_resize();
93
var hash = document.location.hash;
94
if (hash) {
95
document.location.hash = '';
96
document.location.hash = hash;
97
}
98
IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval);
99
// only do this once
100
$([IPython.events]).off('notebook_loaded.Notebook', first_load);
101
};
102
103
$([IPython.events]).on('notebook_loaded.Notebook', first_load);
104
$([IPython.events]).trigger('app_initialized.NotebookApp');
105
IPython.notebook.load_notebook(opts.notebook_name, opts.notebook_path);
106
107
if (marked) {
108
marked.setOptions({
109
gfm : true,
110
tables: true,
111
langPrefix: "language-",
112
highlight: function(code, lang) {
113
if (!lang) {
114
// no language, no highlight
115
return code;
116
}
117
var highlighted;
118
try {
119
highlighted = hljs.highlight(lang, code, false);
120
} catch(err) {
121
highlighted = hljs.highlightAuto(code);
122
}
123
return highlighted.value;
124
}
125
});
126
}
127
});
128
129