$(function(){
  editor = ace.edit("editor");
  editor.setTheme("ace/theme/tomorrow");
  editor.setShowPrintMargin(false);
  editor.getSession().setMode("ace/mode/janus");
  editor.getSession().setTabSize(4);
  editor.getSession().setUseSoftTabs(true);

  var $editor = $("#editor");
  var $outputPane = $("#output-pane");
  var $output = $("#output");
  var $executing = $("#output-pane .executing");

  function setEditorContent(code) {
    editor.setValue(code);
    editor.gotoLine(0);
    removeErrorMarkers();
  }

  function loadCode(hash) {
    var match = hash.match(/#examples\/([a-zA-Z0-9-]+)/);
    if (match) {
      $.get("examples/" + match[1] + ".ja").done(setEditorContent);
      return;
    }

    match = hash.match(/#([a-z0-9]{8})/);
    if (match) {
      $.get("load.php", {hash: match[1]}).done(setEditorContent);
    }
  }

  var prevErrors = [];
  function removeErrorMarkers() {
    var session = editor.getSession();
    for (var i = 0; i < prevErrors.length; ++i) {
      session.removeGutterDecoration(prevErrors[i], "errorGutter");
      prevErrors = [];
    }
  }

  function showOutputPane() {
    $outputPane.show();
    $editor.css("bottom", $outputPane.outerHeight()+"px");
    $editor.resize();
  }

  function hideOutputPane() {
    $outputPane.hide();
    $editor.css("bottom", "0");
    $editor.resize();
  }

  function formatOutput(output) {
    // First line contains the exit code
    var retval = parseInt(output.substr(0, output.indexOf("\n")));
    output = output.substring(output.indexOf("\n") + 1);
    console.log(retval);

    removeErrorMarkers();
    if (retval > 0) {
      var session = editor.getSession();
      var match = output.match(/line (\d+), column (\d+)/);

      if (match) {
        var line = parseInt(match[1]) - 1;
        session.addGutterDecoration(line, "errorGutter");
        prevErrors.push(line);
      }
      $output.html($("<pre>").html(output).addClass("error"));
    } else {
      $output.html($("<pre>").html(output));
    }
  }

  function formatError(data) {
    $output.append(
      '<div class="alert alert-error">An error occured while trying to run the program.</div>'
    );
  }

  function showOutputPane() {
    $outputPane.show();
    $editor.css("bottom", "160px");
    editor.resize();
  }

  $("#examples a").click(function(e) {
    loadCode(e.target.hash);
  });

  $("#run").click(function() {
    showOutputPane();
    $executing.show();
    $output.empty();
    var code = editor.getValue();
    var intSize = $("#options input[name='options-int-size']:checked").val();
    $.post("execute.php", {
      "code": code,
      "intsize": intSize
    })
    .done(formatOutput)
    .fail(formatError)
    .always(function() { $executing.hide(); })
  });

  $("#output-pane button.close").click(function() {
    $("#output-pane").hide();
    $("#editor").css("bottom", "0px");
    editor.resize();
  });

  var sharePopoverVisible = false;
  $("#share").click(function(e) {
    var code = editor.getValue();
    $.post("save.php", {"code": editor.getValue()})
    .done(function(res) {
      var url = location.protocol+'//'+location.host+location.pathname+"#"+res;
      $("#share").popover({
        title: "Share this URL",
        content: "<input value=\""+url+"\" type=text size=40>",
        placement: "bottom",
        html: true,
        trigger: "manual"
      }).popover("show");
      // Select input field in popover
      $(".popover input").select();
      // Prevent click event from bubbling up to document.
      $(".popover").bind("click", function(e) { return false; });
      sharePopoverVisible = true;
    });
    return false;
  });

  $(document).click(function() {
    if (sharePopoverVisible) {
      $("#share").popover("destroy");
    }
  });

  loadCode(location.hash);
});

@@ -1898,36 +1898,36 @@
 html($(%22%3Cpre%3E%22).
-html
+text
 (output).addClas
@@ -1982,20 +1982,20 @@
 %3Cpre%3E%22).
-html
+text
 (output)

Use $.text() instead of $.html() when showing output so HTML is escaped