##// END OF EJS Templates
protect highlight.js against unknown languages...
MinRK -
Show More
@@ -1,115 +1,115
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2011 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // On document ready
10 10 //============================================================================
11 11
12 12
13 13 $(document).ready(function () {
14 14
15 15 // monkey patch CM to be able to syntax highlight cell magics
16 16 // bug reported upstream,
17 17 // see https://github.com/marijnh/CodeMirror2/issues/670
18 18 if(CodeMirror.getMode(1,'text/plain').indent == undefined ){
19 19 console.log('patching CM for undefined indent');
20 20 CodeMirror.modes.null = function() { return {token: function(stream) {stream.skipToEnd();},indent : function(){return 0}}}
21 21 }
22 22
23 23 CodeMirror.patchedGetMode = function(config, mode){
24 24 var cmmode = CodeMirror.getMode(config, mode);
25 25 if(cmmode.indent == null)
26 26 {
27 27 console.log('patch mode "' , mode, '" on the fly');
28 28 cmmode.indent = function(){return 0};
29 29 }
30 30 return cmmode;
31 31 }
32 32 // end monkey patching CodeMirror
33 33
34 34 IPython.mathjaxutils.init();
35 35
36 36 IPython.read_only = $('body').data('readOnly') === 'True';
37 37 $('#ipython-main-app').addClass('border-box-sizing');
38 38 $('div#notebook_panel').addClass('border-box-sizing');
39 39 // The header's bottom border is provided by the menu bar so we remove it.
40 40 $('div#header').css('border-bottom-style','none');
41 41
42 42 var baseProjectUrl = $('body').data('baseProjectUrl')
43 43
44 44 IPython.page = new IPython.Page();
45 45 IPython.layout_manager = new IPython.LayoutManager();
46 46 IPython.pager = new IPython.Pager('div#pager', 'div#pager_splitter');
47 47 IPython.quick_help = new IPython.QuickHelp('span#quick_help_area');
48 48 IPython.login_widget = new IPython.LoginWidget('span#login_widget',{baseProjectUrl:baseProjectUrl});
49 49 IPython.notebook = new IPython.Notebook('div#notebook',{baseProjectUrl:baseProjectUrl, read_only:IPython.read_only});
50 50 IPython.save_widget = new IPython.SaveWidget('span#save_widget');
51 51 IPython.menubar = new IPython.MenuBar('#menubar',{baseProjectUrl:baseProjectUrl})
52 52 IPython.toolbar = new IPython.MainToolBar('#maintoolbar')
53 53 IPython.tooltip = new IPython.Tooltip()
54 54 IPython.notification_area = new IPython.NotificationArea('#notification_area')
55 55 IPython.notification_area.init_notification_widgets();
56 56
57 57 IPython.layout_manager.do_resize();
58 58
59 59 $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+
60 60 '<span id="test2" style="font-weight: bold;">x</span>'+
61 61 '<span id="test3" style="font-style: italic;">x</span></pre></div>')
62 62 var nh = $('#test1').innerHeight();
63 63 var bh = $('#test2').innerHeight();
64 64 var ih = $('#test3').innerHeight();
65 65 if(nh != bh || nh != ih) {
66 66 $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>');
67 67 }
68 68 $('#fonttest').remove();
69 69
70 70 if(IPython.read_only){
71 71 // hide various elements from read-only view
72 72 $('div#pager').remove();
73 73 $('div#pager_splitter').remove();
74 74
75 75 // set the notebook name field as not modifiable
76 76 $('#notebook_name').attr('disabled','disabled')
77 77 }
78 78
79 79 IPython.page.show();
80 80
81 81 IPython.layout_manager.do_resize();
82 82 var first_load = function () {
83 83 IPython.layout_manager.do_resize();
84 84 var hash = document.location.hash;
85 85 if (hash) {
86 86 document.location.hash = '';
87 87 document.location.hash = hash;
88 88 }
89 89 IPython.notebook.set_autosave_interval(IPython.notebook.minimum_autosave_interval);
90 90 // only do this once
91 91 $([IPython.events]).off('notebook_loaded.Notebook', first_load);
92 92 };
93 93
94 94 $([IPython.events]).on('notebook_loaded.Notebook', first_load);
95 95 IPython.notebook.load_notebook($('body').data('notebookId'));
96 96
97 97 if (marked) {
98 98 marked.setOptions({
99 99 gfm : true,
100 100 tables: true,
101 101 langPrefix: "language-",
102 102 highlight: function(code, lang) {
103 103 var highlighted;
104 if (lang) {
104 try {
105 105 highlighted = hljs.highlight(lang, code, false);
106 } else {
106 } catch(err) {
107 107 highlighted = hljs.highlightAuto(code);
108 108 }
109 109 return highlighted.value;
110 110 }
111 111 })
112 112 }
113 113
114 114 });
115 115
General Comments 0
You need to be logged in to leave comments. Login now