Macro/投稿/22
をテンプレートにして作成
Land.to
[
ホーム
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
* 直前の閉じていないHTMLタグを閉じる [#f84eb2ff]
-ページ: [[Macro/投稿]]
-作者: [[gis_dur]]
-カテゴリー: js
-投稿日: 2004-02-26 (木) 20:54:06
** メッセージ [#u2ca1065]
#code(javascript){{
''【closeLastTag.js】
var QUIET_MODE = false;
var REGX_ALL = "</?[\\w\\d]+\\b(.*/>)?|<!--|-->";
var NO_CLOSETAG = "|area|base|basefont|bgsound|br|col|em...
"|hr|img|input|isindex|keygen|link|meta|nextid" +
"|param|spacer|wbr|!doctype|";
var stack_tags = new Array();
var sel_text = "";
var ins_text = "";
var tmp_str = "";
var b_comment = false;
Editor.CancelMode(0);
Editor.InsText("_");
while ( true ) {
Editor.SearchPrev(REGX_ALL, 22);
sel_text = Editor.GetSelectedString(0).toLowerCase();
if ( sel_text=="" ) {
if ( b_comment )
popup_error("コメントの開閉関係が不正です");
if ( stack_tags.length )
popup_error("開始タグの無い終了タグが見つかりました")
break;
}
if ( b_comment ) {
if ( sel_text=="<!--" ) {
b_comment = false;
}
} else {
// -->
if ( sel_text=="-->" ) {
b_comment = true;
// <!--
} else if ( sel_text=="<!--" ) {
ins_text = "-->";
break;
// <.../>
} else if ( sel_text.indexOf("/>")!=-1 ) {
// </...>
} else if ( sel_text.indexOf("</")==0 ) {
sel_text = sel_text.substring(2);
stack_tags.push(sel_text);
// <...>
} else {
sel_text = sel_text.substring(1);
if (NO_CLOSETAG.indexOf("|"+sel_text+"|")!=-1)
continue;
if ( stack_tags.length==0 ) {
ins_text = "</"+ sel_text +">";
break;
} else {
tmp_str = stack_tags.pop();
if ( sel_text!=tmp_str ) {
tmp_str = "タグの包含関係が不正です\n" +
"<" + sel_text + "> ... ... " +
"</" + tmp_str + ">";
popup_error( tmp_str );
break;
}
}
}
}
}
Editor.CancelMode(0);
Editor.Undo(0);
Editor.SearchClearMark(0);
Editor.InsText(ins_text);
function popup_error(err_string) {
if (!QUIET_MODE) {
Editor.SearchClearMark(0);
var shell = new ActiveXObject("WScript.Shell");
shell.Popup(err_string, 0, "HTML 文法エラー", 0);
}
}
}}
----
#comment
終了行:
* 直前の閉じていないHTMLタグを閉じる [#f84eb2ff]
-ページ: [[Macro/投稿]]
-作者: [[gis_dur]]
-カテゴリー: js
-投稿日: 2004-02-26 (木) 20:54:06
** メッセージ [#u2ca1065]
#code(javascript){{
''【closeLastTag.js】
var QUIET_MODE = false;
var REGX_ALL = "</?[\\w\\d]+\\b(.*/>)?|<!--|-->";
var NO_CLOSETAG = "|area|base|basefont|bgsound|br|col|em...
"|hr|img|input|isindex|keygen|link|meta|nextid" +
"|param|spacer|wbr|!doctype|";
var stack_tags = new Array();
var sel_text = "";
var ins_text = "";
var tmp_str = "";
var b_comment = false;
Editor.CancelMode(0);
Editor.InsText("_");
while ( true ) {
Editor.SearchPrev(REGX_ALL, 22);
sel_text = Editor.GetSelectedString(0).toLowerCase();
if ( sel_text=="" ) {
if ( b_comment )
popup_error("コメントの開閉関係が不正です");
if ( stack_tags.length )
popup_error("開始タグの無い終了タグが見つかりました")
break;
}
if ( b_comment ) {
if ( sel_text=="<!--" ) {
b_comment = false;
}
} else {
// -->
if ( sel_text=="-->" ) {
b_comment = true;
// <!--
} else if ( sel_text=="<!--" ) {
ins_text = "-->";
break;
// <.../>
} else if ( sel_text.indexOf("/>")!=-1 ) {
// </...>
} else if ( sel_text.indexOf("</")==0 ) {
sel_text = sel_text.substring(2);
stack_tags.push(sel_text);
// <...>
} else {
sel_text = sel_text.substring(1);
if (NO_CLOSETAG.indexOf("|"+sel_text+"|")!=-1)
continue;
if ( stack_tags.length==0 ) {
ins_text = "</"+ sel_text +">";
break;
} else {
tmp_str = stack_tags.pop();
if ( sel_text!=tmp_str ) {
tmp_str = "タグの包含関係が不正です\n" +
"<" + sel_text + "> ... ... " +
"</" + tmp_str + ">";
popup_error( tmp_str );
break;
}
}
}
}
}
Editor.CancelMode(0);
Editor.Undo(0);
Editor.SearchClearMark(0);
Editor.InsText(ins_text);
function popup_error(err_string) {
if (!QUIET_MODE) {
Editor.SearchClearMark(0);
var shell = new ActiveXObject("WScript.Shell");
shell.Popup(err_string, 0, "HTML 文法エラー", 0);
}
}
}}
----
#comment
ページ名: