Repository navigation
Expand file tree
/
Copy pathnotebook.js
More file actions
93 lines (88 loc) · 2.55 KB
/
Copy pathnotebook.js
File metadata and controls
93 lines (88 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
$.ajaxSetup({
url: client_id,
dataType: "json"
})
$(document).ready(function() {
heartbeat()
comet = new CometGetter()
manager = new Manager("messages")
statusbar = new StatusBar("statusbar")
kernhistory = new History("history .inside")
//Startup POST, set some globals
$.ajax({
type: "POST",
data: {type:"connect"},
success: function(json, status, request) {
username = json.parent_header.username
session = json.header.session
exec_count = json.content.execution_count
manager.get().activate()
}
})
})
function xmlencode(string) {
return string.replace(/\&/g,'&'+'amp;')
.replace(/</g,'&'+'lt;')
.replace(/>/g,'&'+'gt;')
.replace(/\'/g,'&'+'apos;')
.replace(/\"/g,'&'+'quot;')
.replace(/`/g,'&'+'#96;')
}
attrib = {
"30":"cblack", "31":"cred",
"32":"cgreen", "33":"cyellow",
"34":"cblue", "36":"ccyan",
"37":"cwhite", "01":"cbold"}
function fixConsole(txt) {
//Fixes escaped console commands, IE colors. Turns them into HTML
//Unfortunately, the "semantics" of html and console are very
//different, so fancy things *will* break
txt = xmlencode(txt)
var re = /\033\[([\d;]*?)m/
var opened = false
var cmds = []
var opener = ""
var closer = ""
while (re.test(txt)) {
var cmds = txt.match(re)[1].split(";")
closer = opened?"</span>":""
opened = cmds.length > 1 || cmds[0] != 0
var rep = []
for (var i in cmds)
if (typeof(attrib[cmds[i]]) != "undefined")
rep.push(attrib[cmds[i]])
opener = rep.length > 0?"<span class=\""+rep.join(" ")+"\">":""
txt = txt.replace(re, closer + opener)
}
if (opened) txt += "</span>"
return txt.trim()
}
function mod(x, y) {
return ((x%y)+y)%y;
}
function inspect(obj) {
if (obj instanceof Object) {
var str = []
for (var i in obj)
str.push(i+": "+inspect(obj[i]).replace("\n", "\n\t"))
return "{\n\t"+str.join("\n\t")+"\n}\n"
} else {
try {
return obj.toString()
} catch (e) {
}
return ""
}
}
var dedentKeys = /(raise|return|break|continue|yield|pass)/g
function checkIndent(code, pos) {
code = code.slice(0,pos).split("\n")
//Second to last one, the last one is the newline
var last = code[code.length-2].trim()
if (last[last.length-1] == ":")
return 1
else if (dedentKeys.test(last))
return -1
else
return 0
}