0

TiddlyWiki uses the folowing markup to display text as code :

{{{
your code here
}}}

I did this script to display MATLAB files inline

<script>
var p;
 if (document.all){
   // For IE, create an ActiveX Object instance
   p = new ActiveXObject("Microsoft.XMLHTTP");
 }
 else {
   // For mozilla, create an instance of XMLHttpRequest.
   p = new XMLHttpRequest();
 }
 p.open("GET","$1",false);
 p.send(null);
wikify(p.responseText,place);
</script>

Where $1 is a .m file url.

This code works, the .m file content is finely displayed.

I just don't manage to concatenate p.responseText with brace to display nicely the .m file content.

Can you please help me ?

JBo
  • 43
  • 1
  • 6
  • possible duplicate of [How to return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call) – Andreas Apr 15 '15 at 13:52
  • And there the second most upvoted [answer](http://stackoverflow.com/a/16825593/402037) – Andreas Apr 15 '15 at 13:53
  • @Andreas I have paid close attention to the answer you referred to but I don't understand how it can help me here. My javascrip skills are very low, so it may be the reason why... However my question is about Concatenation. I may improve the Get part but it already works. – JBo Apr 16 '15 at 09:35
  • Sorry... :( I've missed the **false** in the `.open(..., false)` call. I thought it is an asynchronous call and therefore `p.responseText` would be `undefined` when you're calling `wikify(p.responseText, place)` right after the `.send()` – Andreas Apr 16 '15 at 10:24
  • 1
    Did you try `wikify("{{{" + p.responseText + "}}}",place);`? – Karl Knechtel Sep 07 '15 at 17:50
  • Probably `wikify("{{{\n" + p.responseText + "\n}}}",place);`, not `wikify("{{{" + p.responseText + "}}}",place);` – YakovL Apr 15 '16 at 13:34
  • @YakovL you're right. Works with `wikify("{{{\n" + p.responseText + "\n}}}",place);` Thanks a lot. – JBo Apr 18 '16 at 07:13
  • Right, let's add an answer and accept it so that others will find it quickly. – YakovL Apr 18 '16 at 10:16

1 Answers1

0

So, the solution is to concatenate the following wrapper to the content:

wikify("{{{\n" + p.responseText + "\n}}}",place);
YakovL
  • 7,557
  • 12
  • 62
  • 102