##// END OF EJS Templates
Add code highlighting to markdown cells.
Stefan van der Walt -
Show More
@@ -0,0 +1,1 b''
1 .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} No newline at end of file
@@ -0,0 +1,28 b''
1 var q=null;window.PR_SHOULD_USE_CONTINUATION=!0;
2 (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a=
3 [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c<i;++c){var j=f[c];if(/\\[bdsw]/i.test(j))a.push(j);else{var j=m(j),d;c+2<i&&"-"===f[c+1]?(d=m(f[c+2]),c+=2):d=j;b.push([j,d]);d<65||j>122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;c<b.length;++c)i=b[c],i[0]<=j[1]+1?j[1]=Math.max(j[1],i[1]):f.push(j=i);b=["["];o&&b.push("^");b.push.apply(b,a);for(c=0;c<
4 f.length;++c)i=f[c],b.push(e(i[0])),i[1]>i[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c<b;++c){var j=f[c];j==="("?++i:"\\"===j.charAt(0)&&(j=+j.substring(1))&&j<=i&&(d[j]=-1)}for(c=1;c<d.length;++c)-1===d[c]&&(d[c]=++t);for(i=c=0;c<b;++c)j=f[c],j==="("?(++i,d[i]===void 0&&(f[c]="(?:")):"\\"===j.charAt(0)&&
5 (j=+j.substring(1))&&j<=i&&(f[c]="\\"+d[i]);for(i=c=0;c<b;++c)"^"===f[c]&&"^"!==f[c+1]&&(f[c]="");if(a.ignoreCase&&s)for(c=0;c<b;++c)j=f[c],a=j.charAt(0),j.length>=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p<d;++p){var g=a[p];if(g.ignoreCase)l=!0;else if(/[a-z]/i.test(g.source.replace(/\\u[\da-f]{4}|\\x[\da-f]{2}|\\[^UXux]/gi,""))){s=!0;l=!1;break}}for(var r=
6 {b:8,t:9,n:10,v:11,f:12,r:13},n=[],p=0,d=a.length;p<d;++p){g=a[p];if(g.global||g.multiline)throw Error(""+g);n.push("(?:"+y(g)+")")}return RegExp(n.join("|"),l?"gi":"g")}function M(a){function m(a){switch(a.nodeType){case 1:if(e.test(a.className))break;for(var g=a.firstChild;g;g=g.nextSibling)m(g);g=a.nodeName;if("BR"===g||"LI"===g)h[s]="\n",t[s<<1]=y++,t[s++<<1|1]=a;break;case 3:case 4:g=a.nodeValue,g.length&&(g=p?g.replace(/\r\n?/g,"\n"):g.replace(/[\t\n\r ]+/g," "),h[s]=g,t[s<<1]=y,y+=g.length,
7 t[s++<<1|1]=a)}}var e=/(?:^|\s)nocode(?:\s|$)/,h=[],y=0,t=[],s=0,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=document.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);m(a);return{a:h.join("").replace(/\n$/,""),c:t}}function B(a,m,e,h){m&&(a={a:m,d:a},e(a),h.push.apply(h,a.e))}function x(a,m){function e(a){for(var l=a.d,p=[l,"pln"],d=0,g=a.a.match(y)||[],r={},n=0,z=g.length;n<z;++n){var f=g[n],b=r[f],o=void 0,c;if(typeof b===
8 "string")c=!1;else{var i=h[f.charAt(0)];if(i)o=f.match(i[1]),b=i[0];else{for(c=0;c<t;++c)if(i=m[c],o=f.match(i[1])){b=i[0];break}o||(b="pln")}if((c=b.length>=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m),
9 l=[],p={},d=0,g=e.length;d<g;++d){var r=e[d],n=r[3];if(n)for(var k=n.length;--k>=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/,
10 q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/,
11 q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g,
12 "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a),
13 a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e}
14 for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g<d.length;++g)e(d[g]);m===(m|0)&&d[0].setAttribute("value",
15 m);var r=s.createElement("OL");r.className="linenums";for(var n=Math.max(0,m-1|0)||0,g=0,z=d.length;g<z;++g)l=d[g],l.className="L"+(g+n)%10,l.firstChild||l.appendChild(s.createTextNode("\xa0")),r.appendChild(l);a.appendChild(r)}function k(a,m){for(var e=m.length;--e>=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*</.test(m)?"default-markup":"default-code";return A[a]}function E(a){var m=
16 a.g;try{var e=M(a.h),h=e.a;a.a=h;a.c=e.c;a.d=0;C(m,h)(a);var k=/\bMSIE\b/.test(navigator.userAgent),m=/\n/g,t=a.a,s=t.length,e=0,l=a.c,p=l.length,h=0,d=a.e,g=d.length,a=0;d[g]=s;var r,n;for(n=r=0;n<g;)d[n]!==d[n+2]?(d[r++]=d[n++],d[r++]=d[n++]):n+=2;g=r;for(n=r=0;n<g;){for(var z=d[n],f=d[n+1],b=n+2;b+2<=g&&d[b+1]===f;)b+=2;d[r++]=z;d[r++]=f;n=b}for(d.length=r;h<p;){var o=l[h+2]||s,c=d[a+2]||s,b=Math.min(o,c),i=l[h+1],j;if(i.nodeType!==1&&(j=t.substring(e,b))){k&&(j=j.replace(m,"\r"));i.nodeValue=
17 j;var u=i.ownerDocument,v=u.createElement("SPAN");v.className=d[a+1];var x=i.parentNode;x.replaceChild(v,i);v.appendChild(i);e<o&&(l[h+1]=i=u.createTextNode(t.substring(b,o)),x.insertBefore(i,v.nextSibling))}e=b;e>=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"],
18 "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"],
19 H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"],
20 J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+
21 I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^<?]+/],["dec",/^<!\w[^>]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^<xmp\b[^>]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^<script\b[^>]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^<style\b[^>]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),
22 ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css",
23 /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}),
24 ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes",
25 hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p<h.length&&l.now()<e;p++){var n=h[p],k=n.className;if(k.indexOf("prettyprint")>=0){var k=k.match(g),f,b;if(b=
26 !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p<h.length?setTimeout(m,
27 250):a&&a()}for(var e=[document.getElementsByTagName("pre"),document.getElementsByTagName("code"),document.getElementsByTagName("xmp")],h=[],k=0;k<e.length;++k)for(var t=0,s=e[k].length;t<s;++t)h.push(e[k][t]);var e=q,l=Date;l.now||(l={now:function(){return+new Date}});var p=0,d,g=/\blang(?:uage)?-([\w.]+)(?!\S)/;m()};window.PR={createSimpleLexer:x,registerLangHandler:k,sourceDecorator:u,PR_ATTRIB_NAME:"atn",PR_ATTRIB_VALUE:"atv",PR_COMMENT:"com",PR_DECLARATION:"dec",PR_KEYWORD:"kwd",PR_LITERAL:"lit",
28 PR_NOCODE:"nocode",PR_PLAIN:"pln",PR_PUNCTUATION:"pun",PR_SOURCE:"src",PR_STRING:"str",PR_TAG:"tag",PR_TYPE:"typ"}})();
@@ -1,258 +1,270 b''
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2008-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 // TextCell
10 10 //============================================================================
11 11
12 12 var IPython = (function (IPython) {
13 13
14 14 // TextCell base class
15 15
16 16 var TextCell = function (notebook) {
17 17 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
18 18 this.placeholder = this.placeholder || '';
19 19 IPython.Cell.apply(this, arguments);
20 20 this.rendered = false;
21 21 this.cell_type = this.cell_type || 'text';
22 22 };
23 23
24 24
25 25 TextCell.prototype = new IPython.Cell();
26 26
27 27
28 28 TextCell.prototype.create_element = function () {
29 29 var cell = $("<div>").addClass('cell text_cell border-box-sizing');
30 30 cell.attr('tabindex','2');
31 31 var input_area = $('<div/>').addClass('text_cell_input');
32 32 this.code_mirror = CodeMirror(input_area.get(0), {
33 33 indentUnit : 4,
34 34 mode: this.code_mirror_mode,
35 35 theme: 'default',
36 36 value: this.placeholder
37 37 });
38 38 // The tabindex=-1 makes this div focusable.
39 39 var render_area = $('<div/>').addClass('text_cell_render').
40 40 addClass('rendered_html').attr('tabindex','-1');
41 41 cell.append(input_area).append(render_area);
42 42 this.element = cell;
43 43 };
44 44
45 45
46 46 TextCell.prototype.bind_events = function () {
47 47 IPython.Cell.prototype.bind_events.apply(this);
48 48 var that = this;
49 49 this.element.keydown(function (event) {
50 50 if (event.which === 13) {
51 51 if (that.rendered) {
52 52 that.edit();
53 53 event.preventDefault();
54 54 };
55 55 };
56 56 });
57 57 };
58 58
59 59
60 60 TextCell.prototype.select = function () {
61 61 IPython.Cell.prototype.select.apply(this);
62 62 var output = this.element.find("div.text_cell_render");
63 63 output.trigger('focus');
64 64 };
65 65
66 66
67 67 TextCell.prototype.edit = function () {
68 68 if (this.rendered === true) {
69 69 var text_cell = this.element;
70 70 var output = text_cell.find("div.text_cell_render");
71 71 output.hide();
72 72 text_cell.find('div.text_cell_input').show();
73 73 this.code_mirror.focus();
74 74 this.code_mirror.refresh();
75 75 this.rendered = false;
76 76 if (this.get_source() === this.placeholder) {
77 77 this.set_source('');
78 78 };
79 79 };
80 80 };
81 81
82 82
83 83 // Subclasses must define render.
84 84 TextCell.prototype.render = function () {};
85 85
86 86
87 87 TextCell.prototype.config_mathjax = function () {
88 88 var text_cell = this.element;
89 89 var that = this;
90 90 text_cell.click(function () {
91 91 that.edit();
92 92 }).focusout(function () {
93 93 that.render();
94 94 });
95 95
96 96 text_cell.trigger("focusout");
97 97 };
98 98
99 99
100 100 TextCell.prototype.get_source = function() {
101 101 return this.code_mirror.getValue();
102 102 };
103 103
104 104
105 105 TextCell.prototype.set_source = function(text) {
106 106 this.code_mirror.setValue(text);
107 107 this.code_mirror.refresh();
108 108 };
109 109
110 110
111 111 TextCell.prototype.get_rendered = function() {
112 112 return this.element.find('div.text_cell_render').html();
113 113 };
114 114
115 115
116 116 TextCell.prototype.set_rendered = function(text) {
117 117 this.element.find('div.text_cell_render').html(text);
118 118 };
119 119
120 120
121 121 TextCell.prototype.at_top = function () {
122 122 if (this.rendered) {
123 123 return true;
124 124 } else {
125 125 return false;
126 126 }
127 127 };
128 128
129 129
130 130 TextCell.prototype.at_bottom = function () {
131 131 if (this.rendered) {
132 132 return true;
133 133 } else {
134 134 return false;
135 135 }
136 136 };
137 137
138 138
139 139 TextCell.prototype.fromJSON = function (data) {
140 140 if (data.cell_type === this.cell_type) {
141 141 if (data.source !== undefined) {
142 142 this.set_source(data.source);
143 143 this.set_rendered(data.rendered || '');
144 144 this.rendered = false;
145 145 this.render();
146 146 };
147 147 };
148 148 };
149 149
150 150
151 151 TextCell.prototype.toJSON = function () {
152 152 var data = {}
153 153 data.cell_type = this.cell_type;
154 154 data.source = this.get_source();
155 155 return data;
156 156 };
157 157
158 158
159 159 // HTMLCell
160 160
161 161 var HTMLCell = function (notebook) {
162 162 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
163 163 IPython.TextCell.apply(this, arguments);
164 164 this.cell_type = 'html';
165 165 };
166 166
167 167
168 168 HTMLCell.prototype = new TextCell();
169 169
170 170
171 171 HTMLCell.prototype.render = function () {
172 172 if (this.rendered === false) {
173 173 var text = this.get_source();
174 174 if (text === "") {text = this.placeholder;};
175 175 this.set_rendered(text);
176 176 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
177 177 this.element.find('div.text_cell_input').hide();
178 178 this.element.find("div.text_cell_render").show();
179 179 this.rendered = true;
180 180 };
181 181 };
182 182
183 183
184 184 // MarkdownCell
185 185
186 186 var MarkdownCell = function (notebook) {
187 187 this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
188 188 IPython.TextCell.apply(this, arguments);
189 189 this.cell_type = 'markdown';
190 190 };
191 191
192 192
193 193 MarkdownCell.prototype = new TextCell();
194 194
195 195
196 196 MarkdownCell.prototype.render = function () {
197 197 if (this.rendered === false) {
198 198 var text = this.get_source();
199 199 if (text === "") {text = this.placeholder;};
200 200 var html = IPython.markdown_converter.makeHtml(text);
201 201 this.set_rendered(html);
202 202 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
203 203 this.element.find('div.text_cell_input').hide();
204 204 this.element.find("div.text_cell_render").show();
205 var code_snippets = this.element.find("pre > code");
206 code_snippets.replaceWith(function () {
207 var code = $(this).html();
208 /* Substitute br for newlines and &nbsp; for spaces
209 before highlighting, since prettify doesn't
210 preserve those on all browsers */
211 code = code.replace(/(\r\n|\n|\r)/gm, "<br/>");
212 code = code.replace(/ /gm, '&nbsp;');
213 code = prettyPrintOne(code);
214
215 return '<code class="prettyprint">' + code + '</code>';
216 });
205 217 this.rendered = true;
206 218 };
207 219 };
208 220
209 221
210 222 // RSTCell
211 223
212 224 var RSTCell = function (notebook) {
213 225 this.placeholder = "Type *ReStructured Text* and LaTeX: $\\alpha^2$";
214 226 IPython.TextCell.apply(this, arguments);
215 227 this.cell_type = 'rst';
216 228 };
217 229
218 230
219 231 RSTCell.prototype = new TextCell();
220 232
221 233
222 234 RSTCell.prototype.render = function () {
223 235 if (this.rendered === false) {
224 236 var text = this.get_source();
225 237 if (text === "") {text = this.placeholder;};
226 238 var settings = {
227 239 processData : false,
228 240 cache : false,
229 241 type : "POST",
230 242 data : text,
231 243 headers : {'Content-Type': 'application/x-rst'},
232 244 success : $.proxy(this.handle_render,this)
233 245 };
234 246 $.ajax("/rstservice/render", settings);
235 247 this.element.find('div.text_cell_input').hide();
236 248 this.element.find("div.text_cell_render").show();
237 249 this.set_rendered("Rendering...");
238 250 };
239 251 };
240 252
241 253
242 254 RSTCell.prototype.handle_render = function (data, status, xhr) {
243 255 this.set_rendered(data);
244 256 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
245 257 this.rendered = true;
246 258 };
247 259
248 260
249 261 IPython.TextCell = TextCell;
250 262 IPython.HTMLCell = HTMLCell;
251 263 IPython.MarkdownCell = MarkdownCell;
252 264 IPython.RSTCell = RSTCell;
253 265
254 266
255 267 return IPython;
256 268
257 269 }(IPython));
258 270
@@ -1,238 +1,242 b''
1 1 <!DOCTYPE HTML>
2 2 <html>
3 3
4 4 <head>
5 5 <meta charset="utf-8">
6 6
7 7 <title>IPython Notebook</title>
8 8
9 9 <link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" />
10 10 <!-- <link rel="stylesheet" href="static/jquery/css/themes/rocket/jquery-wijmo.css" type="text/css" /> -->
11 11 <!-- <link rel="stylesheet" href="static/jquery/css/themes/smoothness/jquery-ui-1.8.14.custom.css" type="text/css" />-->
12 12
13 13 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" charset="utf-8"></script>
14 14 <!-- <script type='text/javascript' src='static/mathjax/MathJax.js?config=TeX-AMS_HTML' charset='utf-8'></script> -->
15 15 <script type="text/javascript">
16 16 if (typeof MathJax == 'undefined') {
17 17 console.log("Trying to load local copy of MathJax");
18 18 document.write(unescape("%3Cscript type='text/javascript' src='static/mathjax/MathJax.js%3Fconfig=TeX-AMS_HTML' charset='utf-8'%3E%3C/script%3E"));
19 19 }
20 20 </script>
21 21
22 22 <link rel="stylesheet" href="static/codemirror-2.12/lib/codemirror.css">
23 23 <link rel="stylesheet" href="static/codemirror-2.12/mode/rst/rst.css">
24 24 <link rel="stylesheet" href="static/codemirror-2.12/theme/ipython.css">
25 25 <link rel="stylesheet" href="static/codemirror-2.12/theme/default.css">
26 26
27 <link rel="stylesheet" href="static/prettify/prettify.css"/>
28
27 29 <link rel="stylesheet" href="static/css/boilerplate.css" type="text/css" />
28 30 <link rel="stylesheet" href="static/css/layout.css" type="text/css" />
29 31 <link rel="stylesheet" href="static/css/base.css" type="text/css" />
30 32 <link rel="stylesheet" href="static/css/notebook.css" type="text/css" />
31 33 <link rel="stylesheet" href="static/css/renderedhtml.css" type="text/css" />
32 34
33 35
34 36 </head>
35 37
36 38 <body>
37 39
38 40 <div id="header">
39 41 <span id="ipython_notebook"><h1>IPython Notebook</h1></span>
40 42 <span id="save_widget">
41 43 <input type="text" id="notebook_name" size="20"></textarea>
42 44 <span id="notebook_id" style="display:none">{{notebook_id}}</span>
43 45 <button id="save_notebook">Save</button>
44 46 </span>
45 47 <span id="kernel_status">Idle</span>
46 48 </div>
47 49
48 50 <div id="main_app">
49 51
50 52 <div id="left_panel">
51 53
52 54 <div id="notebook_section">
53 55 <h3 class="section_header">Notebook</h3>
54 56 <div class="section_content">
55 57 <div class="section_row">
56 58 <span id="new_open" class="section_row_buttons">
57 59 <button id="new_notebook">New</button>
58 60 <button id="open_notebook">Open</button>
59 61 </span>
60 62 <span class="section_row_header">Actions</span>
61 63 </div>
62 64 <div class="section_row">
63 65 <span>
64 66 <select id="download_format">
65 67 <option value="json">ipynb</option>
66 68 <option value="py">py</option>
67 69 </select>
68 70 </span>
69 71 <span class="section_row_buttons">
70 72 <button id="download_notebook">Download</button>
71 73 </span>
72 74 </div>
73 75 <div class="section_row">
74 76 <span class="section_row_buttons">
75 77 <span id="print_widget">
76 78 <button id="print_notebook">Print</button>
77 79 </span>
78 80 </span>
79 81 </div>
80 82 </div>
81 83 </div>
82 84
83 85 <div id="cell_section">
84 86 <h3 class="section_header">Cell</h3>
85 87 <div class="section_content">
86 88 <div class="section_row">
87 89 <span class="section_row_buttons">
88 90 <button id="delete_cell">Delete</button>
89 91 </span>
90 92 <span class="section_row_header">Actions</span>
91 93 </div>
92 94 <div class="section_row">
93 95 <span id="cell_type" class="section_row_buttons">
94 96 <button id="to_code">Code</button>
95 97 <!-- <button id="to_html">HTML</button>-->
96 98 <button id="to_markdown">Markdown</button>
97 99 </span>
98 100 <span class="button_label">Format</span>
99 101 </div>
100 102 <div class="section_row">
101 103 <span id="cell_output" class="section_row_buttons">
102 104 <button id="toggle_output">Toggle</button>
103 105 <button id="clear_all_output">ClearAll</button>
104 106 </span>
105 107 <span class="button_label">Output</span>
106 108 </div>
107 109 <div class="section_row">
108 110 <span id="insert" class="section_row_buttons">
109 111 <button id="insert_cell_above">Above</button>
110 112 <button id="insert_cell_below">Below</button>
111 113 </span>
112 114 <span class="button_label">Insert</span>
113 115 </div>
114 116 <div class="section_row">
115 117 <span id="move" class="section_row_buttons">
116 118 <button id="move_cell_up">Up</button>
117 119 <button id="move_cell_down">Down</button>
118 120 </span>
119 121 <span class="button_label">Move</span>
120 122 </div>
121 123 <div class="section_row">
122 124 <span id="run_cells" class="section_row_buttons">
123 125 <button id="run_selected_cell">Selected</button>
124 126 <button id="run_all_cells">All</button>
125 127 </span>
126 128 <span class="button_label">Run</span>
127 129 </div>
128 130 <div class="section_row">
129 131 <span id="autoindent_span">
130 132 <input type="checkbox" id="autoindent" checked="true"></input>
131 133 </span>
132 134 <span class="checkbox_label">Autoindent:</span>
133 135 </div>
134 136 </div>
135 137 </div>
136 138
137 139 <div id="kernel_section">
138 140 <h3 class="section_header">Kernel</h3>
139 141 <div class="section_content">
140 142 <div class="section_row">
141 143 <span id="int_restart" class="section_row_buttons">
142 144 <button id="int_kernel">Interrupt</button>
143 145 <button id="restart_kernel">Restart</button>
144 146 </span>
145 147 <span class="section_row_header">Actions</span>
146 148 </div>
147 149 <div class="section_row">
148 150 <span id="kernel_persist">
149 151 <input type="checkbox" id="kill_kernel"></input>
150 152 </span>
151 153 <span class="checkbox_label">Kill kernel upon exit:</span>
152 154 </div>
153 155 </div>
154 156 </div>
155 157
156 158 <div id="help_section">
157 159 <h3 class="section_header">Help</h3>
158 160 <div class="section_content">
159 161 <div class="section_row">
160 162 <span id="help_buttons0" class="section_row_buttons">
161 163 <a id="python_help" href="http://docs.python.org" target="_blank">Python</a>
162 164 <a id="ipython_help" href="http://ipython.org/documentation.html" target="_blank">IPython</a>
163 165 </span>
164 166 <span class="section_row_header">Links</span>
165 167 </div>
166 168 <div class="section_row">
167 169 <span id="help_buttons1" class="section_row_buttons">
168 170 <a id="numpy_help" href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a>
169 171 <a id="scipy_help" href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a>
170 172 </span>
171 173 </div>
172 174 <div class="section_row">
173 175 <span id="help_buttons2" class="section_row_buttons">
174 176 <a id="matplotlib_help" href="http://matplotlib.sourceforge.net/" target="_blank">MPL</a>
175 177 <a id="sympy_help" href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a>
176 178 </span>
177 179 </div>
178 180 <div class="section_row">
179 181 <span class="help_string">run selected cell</span>
180 182 <span class="help_string_label">Shift-Enter :</span>
181 183 </div>
182 184 <div class="section_row">
183 185 <span class="help_string">run in terminal mode</span>
184 186 <span class="help_string_label">Ctrl-Enter :</span>
185 187 </div>
186 188 <div class="section_row">
187 189 <span class="help_string">show keyboard shortcuts</span>
188 190 <span class="help_string_label">Ctrl-m h :</span>
189 191 </div>
190 192 </div>
191 193 </div>
192 194
193 195 </div>
194 196 <div id="left_panel_splitter"></div>
195 197 <div id="notebook_panel">
196 198 <div id="notebook"></div>
197 199 <div id="pager_splitter"></div>
198 200 <div id="pager"></div>
199 201 </div>
200 202
201 203 </div>
202 204
203 205 <script src="static/jquery/js/jquery-1.6.2.min.js" type="text/javascript" charset="utf-8"></script>
204 206 <script src="static/jquery/js/jquery-ui-1.8.14.custom.min.js" type="text/javascript" charset="utf-8"></script>
205 207 <script src="static/jquery/js/jquery.autogrow.js" type="text/javascript" charset="utf-8"></script>
206 208
207 209 <script src="static/codemirror-2.12/lib/codemirror.js" charset="utf-8"></script>
208 210 <script src="static/codemirror-2.12/mode/python/python.js" charset="utf-8"></script>
209 211 <script src="static/codemirror-2.12/mode/htmlmixed/htmlmixed.js" charset="utf-8"></script>
210 212 <script src="static/codemirror-2.12/mode/xml/xml.js" charset="utf-8"></script>
211 213 <script src="static/codemirror-2.12/mode/javascript/javascript.js" charset="utf-8"></script>
212 214 <script src="static/codemirror-2.12/mode/css/css.js" charset="utf-8"></script>
213 215 <script src="static/codemirror-2.12/mode/rst/rst.js" charset="utf-8"></script>
214 216
215 217 <script src="static/pagedown/Markdown.Converter.js" charset="utf-8"></script>
216 218
219 <script src="static/prettify/prettify.js" charset="utf-8"></script>
220
217 221 <script src="static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
218 222 <script src="static/js/utils.js" type="text/javascript" charset="utf-8"></script>
219 223 <script src="static/js/cell.js" type="text/javascript" charset="utf-8"></script>
220 224 <script src="static/js/codecell.js" type="text/javascript" charset="utf-8"></script>
221 225 <script src="static/js/textcell.js" type="text/javascript" charset="utf-8"></script>
222 226 <script src="static/js/kernel.js" type="text/javascript" charset="utf-8"></script>
223 227 <script src="static/js/kernelstatus.js" type="text/javascript" charset="utf-8"></script>
224 228 <script src="static/js/layout.js" type="text/javascript" charset="utf-8"></script>
225 229 <script src="static/js/savewidget.js" type="text/javascript" charset="utf-8"></script>
226 230 <script src="static/js/pager.js" type="text/javascript" charset="utf-8"></script>
227 231 <script src="static/js/panelsection.js" type="text/javascript" charset="utf-8"></script>
228 232 <script src="static/js/printwidget.js" type="text/javascript" charset="utf-8"></script>
229 233 <script src="static/js/leftpanel.js" type="text/javascript" charset="utf-8"></script>
230 234 <script src="static/js/notebook.js" type="text/javascript" charset="utf-8"></script>
231 235 <script src="static/js/notebook_main.js" type="text/javascript" charset="utf-8"></script>
232 236
233 237
234 238 </body>
235 239
236 240 </html>
237 241
238 242
General Comments 0
You need to be logged in to leave comments. Login now