💾 Archived View for gemini.bunburya.eu › newsgroups › gemini › messages › 1646501357.bystand@zzo38co… captured on 2023-06-14 at 14:31:07. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-04-28)
-=-=-=-=-=-=-
From: news@zzo38computer.org.invalid
Subject: Firefox text/gemini
Date: Sat, 05 Mar 2022 09:42:23 -0800
Message-ID: <1646501357.bystand@zzo38computer.org>
I made implementation of the Gemini file format in Firefox; however, I had not
implemented the Gemini protocol yet. It will still work with data: URIs, and
with local files and Gempub (if you associate the .gmi extension with the Gemini
format in the mimeTypes.rdf), and I guess also HTTP(S) (although I have not
tested its use with HTTP(S) so far).
I used the userChrome.js and added the following:
(function() {
var Conv=function() {
this.state=0;
this.in="";
this.out="<"+"HTML application=\"gemini-text\">";
};
var tohtml=function(s) {
return s.replace(/[<>'"&]/g,function(x){return "&#"+x.charCodeAt(0)+";";});
};
Conv.prototype.add=function(s) {
this.in+=s;
var i=this.in.indexOf("\n");
while(i>=0) {
this.addLine(this.in.slice(0,i));
this.in=this.in.slice(i+1);
i=this.in.indexOf("\n");
}
};
Conv.prototype.addLine=function(s) {
var i,z;
if(this.state==0) {
this.state=1;
if(s[0]=="#") this.out+="<"+"title>"+tohtml(s.slice(1))+"</title>\n";
}
if(this.state==3 && s) this.state=1;
if(this.state==1) {
if(s.slice(0,3)=="```") {
this.state=2;
this.out+="<pre>";
} else if(s[0]=="#") {
for(i=1;i<6 && s[i]==="#";i++);
this.out+="<h"+i+">"+tohtml(s.slice(i).trim())+"</h"+i+">";
this.state=3;
} else if(s[0]=="=" && s[1]==">") {
s=s.slice(2).trim();
i=s.indexOf(" ");
if(i>=0) z=s.slice(0,i),s=s.slice(i).trim(); else z=s;
this.out+="<"+"a href=\""+tohtml(z)+"\">"+tohtml(s)+"</a><br>\n";
} else {
this.out+=tohtml(s)+"<br>\n";
}
} else if(this.state==2) {
if(s.slice(0,3)=="```") {
this.state=1;
this.out+="</pre>\n";
} else {
this.out+=tohtml(s)+"\n";
}
}
};
Conv.prototype.read=function() {
var x=this.out;
this.out="";
return x;
};
var G=function(){};
var o=G.prototype={
classDescription: "_geminiFileFormat",
classID: Components.ID("{aac00a22-9c4c-11ec-a2da-002618745416}"),
contractID: "@mozilla.org/streamconv;1?from=text/gemini&to=*/*",
convert: function(stream,fromtype,totype,context) {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
asyncConvertData: function(fromtype,totype,listener,context) {
listener.QueryInterface(Ci.nsIStreamListener);
this.listener=listener;
this.offset=0;
this.pipe=Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
this.pipe.init(false,false,0,0,null);
this.conv=new Conv();
},
getConvertedType: function(type,channel) {
if(type.indexOf(";")!=-1) return "text/html"+type.slice(type.indexOf(";"));
return "text/html";
},
onDataAvailable: function(request,context,stream,offset,count) {
let s=NetUtil.readInputStreamToString(stream,count,{});
this.conv.add(s);
let d=this.conv.read();
this.pipe.outputStream.write(d,d.length);
this.listener.onDataAvailable(request,context,this.pipe.inputStream,this.offset,d.length);
this.offset+=d.length;
},
onStartRequest: function(request,context) {
request.QueryInterface(Ci.nsIChannel);
request.contentType="text/html";
this.listener.onStartRequest(request,context);
},
onStopRequest: function(request,context,status) {
if(this.conv.in) {
this.conv.add("\n");
let d=this.conv.read();
this.pipe.outputStream.write(d,d.length);
this.listener.onDataAvailable(request,context,this.pipe.inputStream,this.offset,d.length);
}
this.listener.onStopRequest(request,context,status);
delete this.listener;
delete this.pipe;
delete this.conv;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIStreamConverter,Ci.nsIStreamListener,Ci.nsIRequestObserver]),
};
var r=Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
r.registerFactory(o.classID,o.classDescription,o.contractID,XPCOMUtils._getFactory(G));
})();
You must also add the appropriate entries into the mimeTypes.rdf file.
There may (probably) be some mistakes; please tell me if you had found any mistakes.
--
Don't laugh at the moon when it is day time in France.
Children: