Created
October 22, 2009 11:56
-
-
Save kyanny/215905 to your computer and use it in GitHub Desktop.
MT形式のデリミタ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use Test::Base; | |
plan tests => 1 * blocks; | |
run_is input => 'expected'; | |
sub delimiter_escape_filter { | |
my $html = shift; | |
my $SEP = qr/^(-{8})(¥n)$/; | |
my $SUBSEP = qr/^(-{5})(¥n)$/; | |
my @lines = split /[¥r¥n|¥r|¥n]/, $html; | |
my $new_html; | |
for my $line (@lines) { | |
$line .= "¥n"; | |
if ($line =~ /$SEP/) { | |
$line =~ s/$SEP/$1<>$2/g; | |
} | |
if ($line =~ /$SUBSEP/) { | |
$line =~ s/$SUBSEP/$1<>$2/g; | |
} | |
$new_html .= $line; | |
} | |
return $new_html; | |
} | |
__END__ | |
=== | |
--- input delimiter_escape_filter | |
----- | |
<div id="content"> | |
<p>I thought what I'd do was, I'd pretend I was one of those deaf-mutes. | |
----- or should I ?</p> | |
-------- The Laughing Man, Nine Stories, J.D.Salinger. | |
</div> | |
-------- | |
--- expected | |
-----<> | |
<div id="content"> | |
<p>I thought what I'd do was, I'd pretend I was one of those deaf-mutes. | |
----- or should I ?</p> | |
-------- The Laughing Man, Nine Stories, J.D.Salinger. | |
</div> | |
--------<> | |
--- LAST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment