ACE Editor reporting Javascript scoping errors incorrectly



Please look at the following two successive Javascript blocks in a single file. I am calling the write2doc function defined in the first script block in the code in the second block.The ACE editor is flagging this as a syntax error (lines flagged with yellow ! marks) because it looks like it cannot connect the rwo script blocks during scoping analysis. The program runs fine but showing these syntax errors incorrectly is bothersome in my view. If any one has an insight into fixing this problem, please let me know. I have not enabled any particular JS library for the ACE editor and left the defaults. – Raj

  <script type="text/javascript">
    function write2doc(str) {
      var importDoc = document.currentScript.ownerDocument;
      var warning_div = importDoc.getElementById("warning");
	    var div = importDoc.createElement("div");
	    div.innerHTML = str;
  <script type="text/javascript">
    write2doc("Hello 1<br>");
    write2doc("Hello 2<br>");

<div id="warning">
  <style scoped>
    h3 {
      color: red;
  <script type="text/javascript">
    write2doc("Hello 3<br>");
  <p>This page is under construction</p>


Sorry my sample code did not go through. Here it is:


How do I add Javascript code to a post?