[TWC] trunk remote file for display

34 views
Skip to first unread message

julien23

unread,
Sep 22, 2015, 4:34:49 AM9/22/15
to tiddl...@googlegroups.com
Hi all

I am use to display remote code within TW using for example :

<<tiddler UrlContentScript with:../look_app15_raw/matlab/Emt27PowerFilter.m>>

with [[UrlContentScript]] :

<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>


Sometime I would like to trunck the remote file to display for example only lines 5 to 9.
Can you please help me modify my script ?

Thank you

JBo

Tobias Beer

unread,
Sep 22, 2015, 5:13:28 AM9/22/15
to TiddlyWiki
Hi Julien,
 
wikify(p.responseText,place);

Sometime I would like to trunck the remote file to display for example only lines 5 to 9.

=>

var out = p.responseText.split("\n");
out = out.splice(5, out.length-9);
wikify
(out.join("\n"),place);

Best wishes,

— tb

julien23

unread,
Sep 22, 2015, 6:03:15 AM9/22/15
to TiddlyWiki
Hi Tobias

Thank you for quick and good idea.

I made it work with :
out = out.splice(5-1,9-5+1);

Final with parametrization :

<<tiddler UrlContentScriptStartEnd with:../look_app15_raw/matlab/Emt27PowerFilter.m 5 9>>

with [[UrlContentScriptStartEnd]] :

<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);
var out = p.responseText.split("\n");

out
= out.splice($2-1,$3-$2+1);
wikify
(out.join("\n"),place);
</script>

Thanks a lot

JBo
Reply all
Reply to author
Forward
0 new messages