用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - perl代码库

perl ASCII转换到HTML

2012-10-15 作者: 神马举报

[perl]代码库

#-----------------------------
# download the following standalone program
#!/usr/bin/perl -w -p00
# text2html - trivial html encoding of normal text
# -p means apply this script to each record.
# -00 mean that a record is now a paragraph

use HTML::Entities;
$_ = encode_entities ( $_, "\200-\377" );

if ( /^\s/ )
{
# Paragraphs beginning with whitespace are wrapped in <PRE>
	s { ( .* ) $}        {<PRE>\n$1</PRE>\n} s;
# indented verbatim
}
else
{
	s {^ ( >.* ) }       {$1<BR>} gm;
# quoted text
s {<URL:
	   ( .*? ) >}    {<A HREF="$1">$1</A>} gs         # embedded URL  (good)
	                          ||
s { ( http:\S+ ) }   {<A HREF="$1">$1</A>} gs;
# guessed URL   (bad)
	s {\* ( \S+ ) \*}    {<STRONG>$1</STRONG>} g;
# this is *bold* here
	s {\b_ ( \S+ ) \_\b} {<EM>$1</EM>} g;
# this is _italics_ here
	s {^}            {<P>\n};
# add paragraph tag
}

#-----------------------------
BEGIN
{
	print "<TABLE>";
	$_ = encode_entities ( scalar <> );
	s/\n\s+/ /g;
# continuation lines
	while ( /^ ( \S+?: ) \s* ( .* ) $/gm )
	{
# parse heading
		print "<TR><TH ALIGN='LEFT'>$1</TH><TD>$2</TD></TR>\n";
	}
	print "</TABLE><HR>";
}
#-----------------------------


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...