Implemented Unflow for plaintext content
This commit is contained in:
+23
-1
@@ -10,6 +10,24 @@ Hi01379 = (function(psGopherRequest) {
|
||||
return str.replace(/[&<>]/g, function(tag) {return tagsToReplace[tag] || tag})
|
||||
}
|
||||
|
||||
function unphlow(str) { // Unphlow algorithm implementation
|
||||
var lines=str.split('\n'), line, l = lines.length, i, buf = '', out = []
|
||||
for(i=0;i<l;i++) {
|
||||
line = lines[i].trim() // remove all leading/trailing whitespace-class chars
|
||||
if(line.length) // if the line is not empty, just append it and a whitespace to the buffer
|
||||
buf += line + ' '
|
||||
else { // output logic
|
||||
out.push(buf, '')
|
||||
buf = ''
|
||||
}
|
||||
}
|
||||
if(buf.length) // process the remaining output
|
||||
out.push(buf)
|
||||
return out.map(function(s) { // final whitespace sanitation
|
||||
return s.replace(/\s+/g, ' ').trim()
|
||||
}).join('\n')
|
||||
}
|
||||
|
||||
function gophermapToHTML(gmap, chost, cport) {
|
||||
if(!cport) cport = 70
|
||||
if(!chost) chost = 'localhost'
|
||||
@@ -98,13 +116,17 @@ Hi01379 = (function(psGopherRequest) {
|
||||
})
|
||||
}
|
||||
else { // assuming text content otherwise
|
||||
var output = (new TextDecoder).decode(rawdata), ctype = 'text/plain' // defaulting to type 0
|
||||
var output = (new TextDecoder).decode(rawdata), ctype = 'text/plain', // defaulting to type 0
|
||||
wo = '' // wrapper-friendly output
|
||||
if(type == '1' || type == '7') { // gophermap
|
||||
output = gophermapToHTML(output, resource[2], resource[3])
|
||||
ctype = 'text/html'
|
||||
wo = output
|
||||
}
|
||||
else wo = unphlow(output)
|
||||
successCb({
|
||||
content: output,
|
||||
contentWf: wo,
|
||||
contentType: ctype,
|
||||
serviceMsg: type + ' ' + resource[1]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user