[첫화면으로]UseModWiki소스수정/Vim플러그인

마지막으로 [b]

1. Vim 플러그인
1.1. 알려진 문제점
1.2. plugin/vim.pl 추가
1.3. wiki.css 수정
1.4. 추가 업데이트 내역
1.5. 사용자 의견

1. Vim 플러그인

사용자입력을그대로출력하기의 경우 지원하는 신택스가 몇 개 되지 않는다. 이 플러그인은 vim 을 호출하여 vim이 syntax highlight를 지원하는 언어 코드를 html로 변환하여 출력한다. 박원규님의 [모니위키]에 있는 vim.php 파일을 참조하였다.

 {{{#!vim [c|sh|...] [number]
 code
 }}}

#!/usr/bin/perl
if ($condition) {
    print "Hello, World!\n";
}

1.1. 알려진 문제점

vim 6.4 이후부터, 변환된 출력의 글꼴 색상이 매우 이상하게 나오고 불필요해보이는 밑줄까지 그어져서 나오는 문제가 있다.

현재 딱히 해결방법은 없고, GyparkWiki에서는 다음과 같이 임시로 처리해둔 상태:

sub plugin_vim {
    my ($content, @opt) = @_;
#    my $vim = "vim";       # PATH of vim
    my $vim = "/home/gypark/local/bin/vim63";       # 이런 식으로
    my $tohtml = "syntax/2html.vim";
    ...
}

1.2. plugin/vim.pl 추가

# vim plugin
# 박원규님의 MoniWiki 의 vim.php 의 코드를 흉내내었음.
#
# usage :
# {{{#!vim sh|c|sh|.. [number]
# some codes
# }}}

sub plugin_vim {
    my ($content, @opt) = @_;
    my $vim = "vim";        # PATH of vim
    my $tohtml = "syntax/2html.vim";
    my $text;
    my $status;
    my $option;

    my $type = "nosyntax";
    foreach my $opt (@opt) {
        if ($opt eq "number") {
            $option='+"set number" ';
        } elsif ($opt =~ /^\w+$/) {
            $type = $opt;
        }
    }
    $content =~ s/\r//g;

# html파일의 이름 결정
    my $hash;
    my $hasMD5 = eval "require Digest::MD5;";
    if ($hasMD5) {
        $hash = Digest::MD5::md5_base64($content.join('',@opt));
    } else {
        $hash = crypt($content, $HashKey);
    }
    $hash =~ s/(\W)/uc sprintf "_%02x", ord($1)/eg;

    my $hashhtml = "$hash.html";
    my $VimDir = "$UploadDir/vim";

    if ($hasMD5 and -f "$VimDir/$hashhtml" && not -z "$VimDir/$hashhtml") {
        # 이미 생성되어 캐쉬에 있음
        ($status, $text) = &ReadFile("$VimDir/$hashhtml");

        return $text if $status;
    }

    # 캐쉬에 없거나, 읽는 데 실패하면 새로 작성
    &CreateDir($UploadDir);
    &CreateDir($VimDir);

    my $hashdir = "$TempDir/$hash";
    if (not -d $hashdir) {
        mkdir($hashdir, 0775) or return "[Unable to create $hash dir]";
    }

    my $pwd = `pwd`;
    $pwd =~ s/(.*)(\n|\r)*/$1/;

    chdir ($hashdir);

# html 생성
    my $tmpi = "$hash.in";
    my $tmpo = "$hash.out";
    open (OUT, ">$tmpi") or return "[Unable to open $tmpi file]";
    print OUT  $content;
    close(OUT);

    open SAVEOUT, ">&STDOUT";
    open SAVEERR, ">&STDERR";
    open STDOUT, ">hash.log";
    open STDERR, ">&STDOUT";

    qx($vim -T xterm -e -s $tmpi +"set enc=$HttpCharset" +"syntax on" +"set syntax=$type" $option +"ru! $tohtml" +"wq! $tmpo" +q);

    close STDOUT;
    close STDERR;
    open STDOUT, ">&SAVEOUT";
    open STDERR, ">&SAVEERR";

    # html 가공 및 옮김
    ($status, $text) = &ReadFile("$tmpo");
    if (!$status) {
        return undef;
    }
    $text =~ s/<title>.*title>|<\/?head>|<\/?html>|<meta.*>|<\/?body.*>//g;
    $text =~ s/^.*?<pre>/<pre class='vim'>/gs;
    $text =~ s/^(\s|\n)*//gs;
    $text =~ s/(\s|\n)*$//gs;
    $text .= "\n";

    chdir($pwd);

    # 캐쉬에 저장
    if ($hasMD5 and open (OUT, ">$VimDir/$hashhtml")) {
        print OUT  $text;
        close(OUT);
    }

    unlink (glob("$hashdir/*")) or return "[unlink fail]";
    rmdir ($hashdir) or return "[rmdir fail]";

    return $text;
}

1;

1.3. wiki.css 수정

pre.vim 항목이 추가됨

/* vim plugin */
PRE.vim {
    font: normal normal normal 105%/160% FixedSys, Lucida Console, Courier New, monospace;
    border: 1px solid silver;
    padding: 0.5em 0.5em 0.5em 0.5em;
    white-space:pre;
    text-align:justify;
    width:90%;

    background: black;
    color: #c0c0c0;
}

1.4. 추가 업데이트 내역

ext1.74d - html 파일명을 결정하는 부분 개선. 특수 문자를 삭제하지 않고 아스키코드로 표현하게 함
-- Raymundo 2005-2-12 2:57 pm

ext1.74e

-- Raymundo 2005-2-14 11:10 am

ext1.76a - 미리 보기를 하면 \r 캐릭터 때문에 변환 후 "^M"이 출력되는 문제 수정

-- Raymundo 2005-2-27 9:11 am

ext2.9a - 플러그인의 출력으로 나오는 pre 태그의 스타일을 UseModWiki스타일쉬트에서 지정할 수 있게 수정

-- Raymundo 2008-9-24 8:57 pm

ext2.26a - html_use_css=1 옵션을 주어서, font 태그를 쓰지 않고 span 태그와 스타일쉬트를 사용하는 형태로 변환하게 함. 구체적인 변경 내역은 [vim plugin - CSS를 사용하도록 수정 · 55f970b · gypark/UseModKr] 참고

-- Raymundo 2012-11-25 2:51 am

1.5. 사용자 의견

이름:  
Homepage:
내용:
 

위키위키분류

마지막 편집일: 2012-11-25 2:51 am (변경사항 [d])
2577 hits | Permalink | 변경내역 보기 [h] | 페이지 소스 보기