ラブびあ

ビール。ときどきラブ

xml整形マクロ

xmlのようなタグ付けテキストを、インデントして見やすくする秀丸マクロ。簡易なのでキレイに整形できない場合もあるかも。

disabledraw;

// 下準備
replaceallfast "\t", "" ,regular;
replaceallfast "^ +", "" ,regular;
replaceallfast "\n", "" ,regular;
replaceallfast "><", ">\n<" ,regular;

#indent = 0;
gofiletop;
while ( true ) {
    $line = gettext2(0, lineno, linelen2, lineno);

    // 閉じタグがあったらインデントを浅くする
    if ( strstr($line, "</") == 0 ) {
        #indent = #indent - 1;
    }

    #i = 0;
    while (#i < #indent) {
//      insert "\t";
        insert "    ";
        #i = #i + 1;
    }

    // インデントを深くする(コメント行と閉じタグを含む行は何もしない)
    if (( strrstr($line, "<!--") == -1 ) && ( strrstr($line, "/") == -1 )) {
        #indent = #indent + 1;
    }

    movetolineno 1, lineno + 1;
    if ( lineno == linecount2 ) break;
}
gofiletop;
enabledraw;

endmacro;