Note that there are some explanatory texts on larger screens.

plurals
  1. POFormat and append the text file in a contenteditable div
    text
    copied!<p>How can i format the fetched local text file (C++ code in a text format) to be properly formatted in my contenteditable div (like what the pasting event does, which brings me the desired format). </p> <pre><code>function readSingleFile(evt) { var f = evt.target.files[0]; console.log(f); if (!f) { alert("Failed to load file"); return; } if (f.name.indexOf('.txt') == -1) { alert(f.name + " is not a valid text file."); return; } var r = new FileReader(); r.onload = function(e) { var contents = e.target.result.replace("\n","&lt;br/&gt;"); alert( "Got the file.n" +"name: " + f.name + "n" +"type: " + f.type + "n" +"size: " + f.size + " bytesn" + "contents: " + contents ); document.getElementById('board').innerHTML = contents; } r.readAsText(f); } document.getElementById('fileinput').addEventListener('change', readSingleFile, false); </code></pre> <p><a href="http://jsfiddle.net/vinodlouis/88vtR/3/" rel="nofollow noreferrer">http://jsfiddle.net/vinodlouis/88vtR/3/</a> by <a href="https://stackoverflow.com/users/2523444/vinod-louis">https://stackoverflow.com/users/2523444/vinod-louis</a> </p> <p>try this string as the text file to open. It lost some of the string like (due to not using html entities?)</p> <pre><code>#include&lt;iostream.h&gt; #include&lt;conio.h&gt; int main(){ int grade, passingMark=75; cout&lt;&lt;"Hi there, please enter your mark: "; cin&gt;&gt;grade; if( ((grade &gt;= passingMark)||(grade==35)) &amp;&amp; (grade&lt;101)){ cout&lt;&lt;"\nPass!"; } else if( (grade==74) ){ cout&lt;&lt;endl&lt;&lt;"Almost!"; } else if( (grade&gt;0) &amp;&amp; (grade&lt;70)){ cout&lt;&lt;endl&lt;&lt;"Super Failed!"; } return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload