All pastes #268037 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-12-05 08:12 UTC
rendered paste body
#!/usr/bin/perl

use CGI ('param');
use HTML::Entities;
 
print "Content-type: text/html\n\n";


if( $_ = param('code') )
{
	#encoding html to -non-html-code-
	encode_entities($_);
	
	#---- SPECIAL COMMANDS WITHOUT ;----
	
	
	#normal comment 
	$_ =~ s/(\n?[.]*\#[^\!])(.*[^\n])\n/\<font color\=\"\#009900\"\>$1$2\<\/font\>\n/g;
		
	#bin bash
	$_ =~ s/^(\#\!.*[^\n])\n/\<font color\=\"\#006600\"\>\<b\>$1\<\/b\>\<\/font\>\n/g;
	#use ...
	$_ =~ s/\nuse (.*[^\;])\;/\n\<b\>use\<\/b\> \<i\>$1\<\/i\>\;/g;
	
	
	#---- NORMAL COMMANDS WITH ;----

	#print
	$_ =~ s/(\n?[.]*print) (.+)\;/\<b\>$1\<\/b\> \<font color\=\"\#0000cc\"\>$2\<\/font\>\;/g;
	#if
	$_ =~ s/(\n?[.]*if)[.]*\((.*)\)[.]*\{(.*)\}/\<b\>$1\<\/b\> \(\<i\>$2\<\/i\>\)\n\{\<blockquote\>$3\<\/blockquote\>\}/g;
	#variables
	$_ =~ s/(\$|\%|\@)([a-zA-Z0-9_-]*)/\<b\>\<font color\=\"\#000000\"\>$1\<\/font\>\<\/b\>\<font color\=\"\#cc0000\"\>$2\<\/font\>/g;
	
	
	# new line to br
	$_ =~ s/\n/\<br\/\>/g;
	print $_;
}