[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [gopher] gopher2http



>  > ...
>  > or do you have another idea on how to solve this problem? 
>  > ... 
> 
> I came up with a pretty simple idea: As all gopher content I might want to
> deliver so far is static, I can run a gophermap2html "converter"

I have something like this already for a similar task but it's not really
general-purpose.  That said, it does do some limited markup. It's in Perl.
Have the W filehandle open to your gophermap and it will emit HTML.

-- 
------------------------------------ personal: http://www.cameronkaiser.com/ --
  Cameron Kaiser * Floodgap Systems * www.floodgap.com * ckaiser@floodgap.com
-- Si des purgamentum, purgamentum accipietis. --------------------------------

-- 8< CUT HERE --

#!/usr/bin/perl

$listlevel = 0;
@liststack = ();

while(<W>) {
	next if (/^['"]/);
	if (/\t/) {
		next unless (/HTML$/);
		chomp;
		($ds, $sel, $host, $port, $bletch) = split(/\t/, $_, 5);
		$itype = substr($ds, 0, 1);
		$ds = substr($ds, 1);
		print <<"EOF";
<a class = "gmurl" href = "gopher://$host:$port/${itype}$sel";>$ds</a>
EOF
		next;
	}
	if (/^\s/ && $_ ne "\n" && $_ ne "\r\n") {
		my $thislevel = 0;
		my $listtype;

		chomp;
		$_ .= " ";
		&gmfixfix;
		$thislevel++ while (s/^\s//);
		if (/^[^\#\-\*]/) {
			print;
			next;
		}
		print "</span>\n" if ($spanopen);
		$spanopen = 0;
		$listtype = substr($_, 0, 1);
		$listtype = ($listtype eq '*') ? "ul" : "ol";
		$_ = substr($_, 1);
		s/^\s+//;
		while ($thislevel > $listlevel) {
			$listlevel++;
			unshift(@liststack, $listtype);
			print "<$listtype>";
		}
		while ($thislevel < $listlevel) {
			$listlevel--;
			print "</", shift(@liststack), ">\n";
		}
		print "<li><span class = \"gm$liststack[0]$thislevel\">$_";
		$spanopen = 1;
		next;
	}
	print "</span>\n" if ($spanopen);
	$spanopen = 0;
	while($listlevel) {
		$listlevel--;
		print "</", shift(@liststack), ">\n";
	}
	if (/^[\r\l\n\s]*$/) {
		print "<p>\n";
		next;
	}
	if (s/^<//) { # raw HTML
		print;
		next;
	}
	&gmfixfix;
	s#\s*\**$#</em># if (s#^\*+\s*#<em>#);
	print;
	next;
}

sub gmfixfix { # operates always on $_
	s/</\&lt;/g;
	s/>/\&gt;/g;
	s/``/<span class = "gmem">/g;
	s/''/<\/span>/g;
}

1;


_______________________________________________
Gopher-Project mailing list
Gopher-Project@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/gopher-project



Reply to: