HTML::DoCoMoCSSを使う
絵文字がある場合の処理
use HTML::DoCoMoCSS; use Jcode(); my $inliner = HTML::DoCoMoCSS->new(base_dir => '/path/to/documentroot/'); my $j = Jcode->new(); my $content = qq(<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=shift_jis" /> <link rel="stylesheet" href="/html_docomocss_test.css" /> <style type="text/css"> span { color: #0000FF; } </style> </head> <body> <div class="title">赤い文字</div> <span>青い文字 絵文字(げっそり→F9FCh)(晴れ→F89Fh)</span> <div>今日も、明日も</div> </body> </html>); $content = $inliner->apply($j->set($content, 'cp932')->utf8); print "Content-Type: text/plain; charset=Shift_JIS\n\n", $j->set($content, 'utf8')->fallback(Jcode::FB_XMLCREF)->sjis; exit;
※上記は`encoding="utf-8"`という記述があるが、シフトJISで書かれているものとする
※F9FCh,F89Fhは、シフトJISの16進バイナリコード
【html_docomocss_test.css】
.title { color: red; }
【結果】
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=shift_jis" /> <link rel="stylesheet" href="/html_docomocss_test.css" /> <style type="text/css"> span { color: #0000FF; } </style> </head> <body> <div class="title" style="color:red">赤い文字</div> <span style="color:#0000FF">青い文字 絵文字(げっそり→)(晴れ→)</span> <div>今日も、明日も</div></body> </html>