Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

now with syntax highlighting! and haskell too!

  • Loading branch information...
commit a54de21ee880db1641fefd75edf19eb0994f1f8b 1 parent 0a226b2
Austin Seipp authored
View
2  Makefile
@@ -50,6 +50,8 @@ plugins:
# javascript bindings
$(E) Building mathjax bindings...
$(OPAPB) bsl/js/mathjax.js -o mathjax.opp
+ $(E) Building SHJS bindings...
+ $(OPAPB) bsl/js/shjs.js -o shjs.opp
# Cleaning
clean:
View
5 bsl/js/shjs.js
@@ -0,0 +1,5 @@
+##register shjs_highlight_doc : -> void
+##args()
+{
+ sh_highlightDocument();
+}
View
3  opaque.opack
@@ -6,6 +6,9 @@ src/native.opa
mathjax.opp
src/mathjax.opa
+shjs.opp
+src/shjs.opa
+
--mllopt $(PWD)/bsl/c/upskirt/*.o
upskirt.opp
src/upskirt.opa
View
3  res/sh_haskell.min.js
@@ -0,0 +1,3 @@
+
+if(!this.sh_languages){this.sh_languages={};}
+sh_languages['haskell']=[[[/\b[+-]?(?:(?:0x[A-Fa-f0-9]+)|(?:0[oO][0-7]+)|(?:(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?))u?(?:(?:int(?:8|16|32|64))|L)?\b/g,'sh_number',-1],[/"/g,'sh_string',1],[/'(?:[^\\']{1}|\\[\\'0abfnrtv"&]|\\[\d]+|\\[oO][0-7]+|\\[xX][A-Fa-f0-9]+)'/g,'sh_string',-1],[/'[^\\']{2,}'/g,'sh_regex',-1],[/\b(?:case|class|data|default|deriving|do|else|if|import|in|infix|infixl|infixr|instance|let|module|newtype|of|then|type|where|_)\b/g,'sh_keyword',-1],[/\{-/g,'sh_comment',2],[/(?:[!#$$%*+\.\/<=>\?@\\\^\|\-~:]+)--(?:[!#$$%*+\.\/<=>\?@\\\^\|\-~:]*)/g,'sh_symbol',-1],[/(?:--)(?![!#$$%*+\.\/<=>\?@\\\^\|\-~:]+)/g,'sh_comment',3],[/\b(?:[A-Z][\w']*)\b(?![\.])/g,'sh_type',-1],[/!|#|\$|%|&|\*|\+|\.|\/|<|=|>|\?|@|\\|\^|\||-|~|\(|\)|,|;|\[|\]|`|\{|\}|:/g,'sh_symbol',-1],[/\{|\}/g,'sh_cbracket',-1]],[[/$/g,null,-2],[/\\(?:\\|")/g,null,-1],[/"/g,'sh_string',-2]],[[/-\}/g,'sh_comment',-2],[/\{-/g,'sh_comment',2]],[[/$/g,null,-2]]];
View
4 res/sh_main.min.js
@@ -0,0 +1,4 @@
+if(!this.sh_languages){this.sh_languages={}}var sh_requests={};function sh_isEmailAddress(a){if(/^mailto:/.test(a)){return false}return a.indexOf("@")!==-1}function sh_setHref(b,c,d){var a=d.substring(b[c-2].pos,b[c-1].pos);if(a.length>=2&&a.charAt(0)==="<"&&a.charAt(a.length-1)===">"){a=a.substr(1,a.length-2)}if(sh_isEmailAddress(a)){a="mailto:"+a}b[c-2].node.href=a}function sh_konquerorExec(b){var a=[""];a.index=b.length;a.input=b;return a}function sh_highlightString(B,o){if(/Konqueror/.test(navigator.userAgent)){if(!o.konquered){for(var F=0;F<o.length;F++){for(var H=0;H<o[F].length;H++){var G=o[F][H][0];if(G.source==="$"){G.exec=sh_konquerorExec}}}o.konquered=true}}var N=document.createElement("a");var q=document.createElement("span");var A=[];var j=0;var n=[];var C=0;var k=null;var x=function(i,a){var p=i.length;if(p===0){return}if(!a){var Q=n.length;if(Q!==0){var r=n[Q-1];if(!r[3]){a=r[1]}}}if(k!==a){if(k){A[j++]={pos:C};if(k==="sh_url"){sh_setHref(A,j,B)}}if(a){var P;if(a==="sh_url"){P=N.cloneNode(false)}else{P=q.cloneNode(false)}P.className=a;A[j++]={node:P,pos:C}}}C+=p;k=a};var t=/\r\n|\r|\n/g;t.lastIndex=0;var d=B.length;while(C<d){var v=C;var l;var w;var h=t.exec(B);if(h===null){l=d;w=d}else{l=h.index;w=t.lastIndex}var g=B.substring(v,l);var M=[];for(;;){var I=C-v;var D;var y=n.length;if(y===0){D=0}else{D=n[y-1][2]}var O=o[D];var z=O.length;var m=M[D];if(!m){m=M[D]=[]}var E=null;var u=-1;for(var K=0;K<z;K++){var f;if(K<m.length&&(m[K]===null||I<=m[K].index)){f=m[K]}else{var c=O[K][0];c.lastIndex=I;f=c.exec(g);m[K]=f}if(f!==null&&(E===null||f.index<E.index)){E=f;u=K;if(f.index===I){break}}}if(E===null){x(g.substring(I),null);break}else{if(E.index>I){x(g.substring(I,E.index),null)}var e=O[u];var J=e[1];var b;if(J instanceof Array){for(var L=0;L<J.length;L++){b=E[L+1];x(b,J[L])}}else{b=E[0];x(b,J)}switch(e[2]){case -1:break;case -2:n.pop();break;case -3:n.length=0;break;default:n.push(e);break}}}if(k){A[j++]={pos:C};if(k==="sh_url"){sh_setHref(A,j,B)}k=null}C=w}return A}function sh_getClasses(d){var a=[];var b=d.className;if(b&&b.length>0){var e=b.split(" ");for(var c=0;c<e.length;c++){if(e[c].length>0){a.push(e[c])}}}return a}function sh_addClass(c,a){var d=sh_getClasses(c);for(var b=0;b<d.length;b++){if(a.toLowerCase()===d[b].toLowerCase()){return}}d.push(a);c.className=d.join(" ")}function sh_extractTagsFromNodeList(c,a){var f=c.length;for(var d=0;d<f;d++){var e=c.item(d);switch(e.nodeType){case 1:if(e.nodeName.toLowerCase()==="br"){var b;if(/MSIE/.test(navigator.userAgent)){b="\r"}else{b="\n"}a.text.push(b);a.pos++}else{a.tags.push({node:e.cloneNode(false),pos:a.pos});sh_extractTagsFromNodeList(e.childNodes,a);a.tags.push({pos:a.pos})}break;case 3:case 4:a.text.push(e.data);a.pos+=e.length;break}}}function sh_extractTags(c,b){var a={};a.text=[];a.tags=b;a.pos=0;sh_extractTagsFromNodeList(c.childNodes,a);return a.text.join("")}function sh_mergeTags(d,f){var a=d.length;if(a===0){return f}var c=f.length;if(c===0){return d}var i=[];var e=0;var b=0;while(e<a&&b<c){var h=d[e];var g=f[b];if(h.pos<=g.pos){i.push(h);e++}else{i.push(g);if(f[b+1].pos<=h.pos){b++;i.push(f[b]);b++}else{i.push({pos:h.pos});f[b]={node:g.node.cloneNode(false),pos:h.pos}}}}while(e<a){i.push(d[e]);e++}while(b<c){i.push(f[b]);b++}return i}function sh_insertTags(k,h){var g=document;var l=document.createDocumentFragment();var e=0;var d=k.length;var b=0;var j=h.length;var c=l;while(b<j||e<d){var i;var a;if(e<d){i=k[e];a=i.pos}else{a=j}if(a<=b){if(i.node){var f=i.node;c.appendChild(f);c=f}else{c=c.parentNode}e++}else{c.appendChild(g.createTextNode(h.substring(b,a)));b=a}}return l}function sh_highlightElement(d,g){sh_addClass(d,"sh_sourceCode");var c=[];var e=sh_extractTags(d,c);var f=sh_highlightString(e,g);var b=sh_mergeTags(c,f);var a=sh_insertTags(b,e);while(d.hasChildNodes()){d.removeChild(d.firstChild)}d.appendChild(a)}function sh_getXMLHttpRequest(){if(window.ActiveXObject){return new ActiveXObject("Msxml2.XMLHTTP")}else{if(window.XMLHttpRequest){return new XMLHttpRequest()}}throw"No XMLHttpRequest implementation available"}function sh_load(language,element,prefix,suffix){if(language in sh_requests){sh_requests[language].push(element);return}sh_requests[language]=[element];var request=sh_getXMLHttpRequest();var url=prefix+"sh_"+language+suffix;request.open("GET",url,true);request.onreadystatechange=function(){if(request.readyState===4){try{if(!request.status||request.status===200){eval(request.responseText);var elements=sh_requests[language];for(var i=0;i<elements.length;i++){sh_highlightElement(elements[i],sh_languages[language])}}else{throw"HTTP error: status "+request.status}}finally{request=null}}};request.send(null)}function sh_highlightDocument(g,k){var b=document.getElementsByTagName("pre");for(var e=0;e<b.length;e++){var f=b.item(e);var a=sh_getClasses(f);for(var c=0;c<a.length;c++){var h=a[c].toLowerCase();if(h==="sh_sourcecode"){continue}if(h.substr(0,3)==="sh_"){var d=h.substring(3);if(d in sh_languages){sh_highlightElement(f,sh_languages[d])}else{if(typeof(g)==="string"&&typeof(k)==="string"){sh_load(d,f,g,k)}else{throw'Found <pre> element with class="'+h+'", but no such language exists'}}break}}}};
+
+// Copyright (C) 2007, 2008 gnombat@users.sourceforge.net
+// License: http://shjs.sourceforge.net/doc/gplv3.html
View
1  res/sh_nedit.min.css
@@ -0,0 +1 @@
+pre.sh_sourceCode{background-color:#fff;color:#000;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_keyword{color:#000;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_type{color:#a52a2a;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_string{color:#006400;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_regexp{color:#006400;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_specialchar{color:#2e8b57;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_comment{color:#000;font-weight:normal;font-style:italic;}pre.sh_sourceCode .sh_number{color:#006400;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_preproc{color:#27408b;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_symbol{color:#000;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_function{color:#000;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_cbracket{color:#000;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_url{color:#006400;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_date{color:#000;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_time{color:#000;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_file{color:#000;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_ip{color:#006400;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_name{color:#006400;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_variable{color:#dda0dd;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_oldfile{color:#2e8b57;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_newfile{color:#006400;font-weight:normal;font-style:normal;}pre.sh_sourceCode .sh_difflines{color:#000;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_selector{color:#dda0dd;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_property{color:#000;font-weight:bold;font-style:normal;}pre.sh_sourceCode .sh_value{color:#006400;font-weight:normal;font-style:normal;}
View
20 src/main.opa
@@ -2,6 +2,7 @@ package opaque.main
import opaque.native
import opaque.user
import opaque.mathjax
+import opaque.shjs
import opaque.upskirt
room = Network.cloud("room"): Network.network(xhtml)
@@ -9,7 +10,8 @@ room = Network.cloud("room"): Network.network(xhtml)
@client broadcast(s) =
do Dom.transform([#output <- s])
do Debug.jlog("Now reloading mathjax...")
- MathJax.reload(#output)
+ do MathJax.reload(#output)
+ SHJS.highlight()
update() =
do Debug.jlog("Upskirting entry...")
@@ -24,14 +26,20 @@ start() =
release = get_sys_release()
machine = get_sys_machine()
- <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" />
+ <script type="text/javascript" src="res/sh_main.min.js"/>
+ <script type="text/javascript" src="res/sh_haskell.min.js"/>
+ <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"/>
+
<h1>Hi! This server is using {mem}MB of RAM.</h1>
<p>The server you're using is '{nodename}' (a {sysname}/{machine} machine, version {release})</p>
<br/>
+ <p>Result:</p><br/><div id=#output onready={_ -> Network.add_callback(broadcast, room)}></div>
+ <br/>
<div id=#inputarea>
- <input id=#entry onnewline={_ -> update()} />
- <div class="button" onclick={_ -> update()}>Submit</div>
+ <textarea rows=50 cols=80 id=#entry /><br/>
+ <button type="button" onclick={_ -> update()}>Submit</button>
</div>
- <div id=#output onready={_ -> Network.add_callback(broadcast, room)}></div>
-server = Server.one_page_bundle("Opaque blog", [], [], start)
+
+server = Server.one_page_bundle("Opaque blog", [@static_resource_directory("res")],
+ ["res/sh_nedit.min.css", "res/style.css"], start)
View
5 src/shjs.opa
@@ -0,0 +1,5 @@
+package opaque.shjs
+
+@client SHJS = {{
+ highlight = %%shjs.shjs_highlight_doc%%
+}}
Please sign in to comment.
Something went wrong with that request. Please try again.