1. Taegyoon Kim
  2. ParenJS

Commits

Taegyoon Kim  committed b00109a

Display code's <> properly. Show JS selectively.

  • Participants
  • Parent commits dff9672
  • Branches master

Comments (0)

Files changed (1)

File parenjs.html

View file
 <script>
 function html(s) {
  if(s==undefined) return "";
- return s.toString().replace(/\r\n/g,"<br/>").replace(/\n/g,"<br/>");
+ return s.toString().replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\r\n/g,"<br/>").replace(/\n/g,"<br/>");
 }
 
 function pre(s) {
 }
 
 function evaluateCode(code) {
- var result;
+ var result, jscode, result;
  try{
   jscode = paren.compile(code);
-  result = paren.eval(code);
+  result = html(paren.eval(code));
  }catch (err) {
   result = "<font color=red>" + err.message + "</font>";
  }
- document.getElementById('result').innerHTML +=  "<font color=red>Paren>></font> " + html(code) + "<br/><font color=green>JS>></font> " + html(jscode) + "<font color=blue>" + html(result) + "</font><br/>";
+ document.getElementById('result').innerHTML +=  "<font color=red>></font> " + html(code) + "<br/>" + (document.getElementById('chkShowJS').checked ? "<font color=green>JS></font> " + html(jscode) : "") + "<font color=blue>" + result + "</font><br/>";
 }
 
 function clearResult() { document.getElementById('result').innerHTML = ""; }
 
 function examples() {
- var code = 'paren.VERSION';
- evaluateCode(code);
- code = '; Project Euler Problem 1\n'+
-  '(apply + (filter (fn (x) (|| (== 0 (% x 3)) (== 0 (% x 5)))) (range 1 999 1)))';
- evaluateCode(code);
+ evaluateCode('paren.VERSION');
+ evaluateCode('; Project Euler Problem 1\n'+
+  '(apply + (filter (fn (x) (|| (== 0 (% x 3)) (== 0 (% x 5)))) (range 1 999 1)))');
+ evaluateCode('(paren.compile "(+ 1 2)")');
 }
 
 window.onload=examples;
 </script>
-<body style="FONT-FAMILY: Consolas,'Courier New',Monospace,����ü">
+<body>
 <a href="https://bitbucket.org/ktg/parenjs">Paren</a> Interpreter<br /><br />
 Result:<br />
-<div id=result></div><hr>
+<div id=result style="FONT-FAMILY: Consolas,'Courier New',Monospace,����ü"></div><hr>
 <INPUT onclick='evaluateCode(document.getElementById("textareaCode").value)' value=Evaluate type=button>
-<INPUT onclick=clearResult() value="Clear Result" type=button><br />
+<INPUT onclick=clearResult() value="Clear Result" type=button>
+<input type="checkbox" id="chkShowJS">Show JS</input>
+<br />
 Code:<br />
-<TEXTAREA style="WIDTH: 100%" id=textareaCode rows=20></TEXTAREA> <br />
+<TEXTAREA style="WIDTH: 100%" id=textareaCode rows=20 style="FONT-FAMILY: Consolas,'Courier New',Monospace,����ü"></TEXTAREA> <br />
 </body>