[ 新規 | 編集 | 差分 ] [ 検索 | 一覧 | FrontPage ] [ 履歴 (RSS) | 差分履歴 (RSS) ] [ ログイン ]
【PR】Amazon | SL-C3000 | SL-C1000(3/18発売!) | SL-C860 | SL-6000W | SL-6000L | SL-6000N

WalWiki/カスタマイズ/ValidHTML

編集

不正なHTML出力をしないようにする。

[fix invalid html]

編集

記法によって不正なHTMLが出力される場合があったのでそれを修正。
下記の点が修正されています。

さらにブロック要素の入れ子にも対応しました。
↓のような記述が可能になりました。

back_push()変更

編集
# yakty del [fix invalid html] start
#sub back_push {
#    my ($tag, $level, $savedref, $resultref, $attr) = @_;
#    while (@$savedref > $level) {
#        push(@$resultref, shift(@$savedref));
#    }
#    if ($savedref->[0] ne "</$tag>") {
#        push(@$resultref, splice(@$savedref));
#    }
#    while (@$savedref < $level) {
#        unshift(@$savedref, "</$tag>");
#        push(@$resultref, "<$tag$attr>");
#    }
#}
# yakty del [fix invalid html] end
# yakty add [fix invalid html] start
sub back_push {
    #my ($tag, $level, $savedref, $resultref, $attr) = @_;
    my ($tag, $level, $savedref, $resultref, $attr, $ignoreref) = @_;
    while(grep(/$tag/, @$savedref) > $level){
        push(@$resultref, shift(@$savedref));
    }
    if($savedref->[0] eq "</p>"){
        push(@$resultref, shift(@$savedref));
    }
    while($savedref->[0] ne "</$tag>"
            and $savedref->[0] ne "</li>"
            and grep(/<\/li>/, @$savedref) > 0){
        push(@$resultref, shift(@$savedref));
    }
    #while(@$savedref and $savedref->[0] ne "</$tag>"){
    while($savedref->[0] ne "</$tag>" and grep(/<\/$tag>/, @$savedref) >= $level){
        push(@$resultref, shift(@$savedref));
    }
    while (grep(/$tag/, @$savedref) < $level) {
        unshift(@$savedref, "</$tag>");
        push(@$resultref, "<$tag$attr>");
    }
}
# yakty add [fix invalid html] end

text_to_html()内の変更

編集
    my (@txt) = split(/\n/, $txt);
    my (@toc);
    my $tocnum = 0;
    my (@saved, @result);
    #unshift(@saved, "</p>");                # yakty del [fix invalid html]
    #push(@result, "<p>");                   # yakty del [fix invalid html]
#   foreach (@txt) {
    for (my $line = 0; $line < @txt; $line++) {
        } elsif (/^(-{1,3})(.*)/) {
            &back_push('ul', length($1), \@saved, \@result);
            #push(@result, '<li>' . &inline($2) . '</li>');                   # yakty del [fix invalid html]
            # yakty add [fix invalid html] start
            if($form{mypage} eq $RecentChanges){
            	push(@result, '<li>' . &inline($2) . '</li>');
            } else {
                push(@result, shift(@saved)) if($saved[0] eq '</li>');
                push(@result, '<li>' . &inline($2));
                unshift(@saved,'</li>');
            }
            # yakty add [fix invalid html] end
        } elsif (/^(>{1,3})(.*)/) {
            &back_push('blockquote', length($1), \@saved, \@result);
            push(@result, '<p>' . &inline($2));
            unshift(@saved, '</p>');                     # yakty add [fix invalid html]
#       } elsif (/^\s*$/) {                       # Walrus del [convine pre]
        } elsif (/^[\x0D\x0A]*$/) {               # Walrus add [convine pre]
            push(@result, splice(@saved));
            #unshift(@saved, "</p>");             # yakty del [fix invalid html]
            #push(@result, "<p>");                # yakty del [fix invalid html]
        } else {
            # yakty add [fix invalid html] start
            if($#saved < 0){
                unshift(@saved, "</p>");
                push(@result, "<p>");
            }
            # yakty add [fix invalid html] end
            push(@result, &inline($_));
            # yakty add [keep newline] start
            if($saved[0] eq '</p>'){
                push(@result, '<br />'); 
            }
            # yakty add [keep newline] end
        }
       foreach (@toc) {
           if (/^(-{1,3})(.*)/) {
               &back_push('ul', length($1), \@tocsaved, \@tocresult);
               #push(@tocresult, '<li>' . $2 . '</li>');      # yakty del [fix invalid html]
               # yakty add [fix invalid html] start
               push(@tocresult, shift(@tocsaved)) if($tocsaved[0] eq '</li>');
               push(@tocresult, '<li>' . $2);
               unshift(@tocsaved,'</li>');
               # yakty add [fix invalid html] end
           }
       }

make_link()内の変更

編集
        #if ($name =~ /^(https?|ftp):[^\?]+\.(gif|png|jpe?g)$/ and $use_autoimg) {           # yakty del [fix invalid html]
        #    $escapedname = qq(<img src="$escapedname">);                                    # yakty del [fix invalid html]
        if ($name =~ /^(https?|ftp):[^\?]+?([^\/]+\.(gif|png|jpe?g))$/ and $use_autoimg) {   # yakty add [fix invalid html]
            $escapedname = qq(<img src="$escapedname" alt="$2">);                            # yakty add [fix invalid html]
            return $escapedname if ($name eq $chunk);
        }

03676