From 11131b51f85bf7aeca8dbb38c5d683ac0e352f64 Mon Sep 17 00:00:00 2001 From: Hyungsuk Hong Date: Fri, 23 Nov 2012 00:19:44 +0900 Subject: [PATCH] add `font2span` subroutine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit kindle 에서의 원활한 소스코드 하이라이팅을 위해 vim 에서 html 에서 font 태그를 embed stylesheet 로 대체 #!/usr/bin/env perl use strict; use warnings; use 5.010; 가 #!/usr/bin/env perl use strict; use warnings; use 5.010; 로 바뀜 --- plugin/vim.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugin/vim.pl b/plugin/vim.pl index b43254e..1ccadb0 100644 --- a/plugin/vim.pl +++ b/plugin/vim.pl @@ -84,6 +84,8 @@ sub plugin_vim { $text =~ s/(\s|\n)*$//gs; $text .= "\n"; + $text = font2span($text); + chdir($pwd); # 캐쉬에 저장 @@ -98,4 +100,24 @@ sub plugin_vim { return $text; } +sub font2span { + my $html = shift; + + my @colors = $html =~ m/color="#([^"]+)"/g; + my %colorMap; + $colorMap{$_}++ for @colors; + @colors = keys %colorMap; + + my $style = "\n"; + $html = $style . $html; + $html =~ s/font color="#/span class="_/g; + $html =~ s/\/font/\/span/g; + return $html; +} + 1;