|
直前の閉じていないHTMLタグを閉じる
- ページ: Macro/投稿
- 作者: gis_dur?
- カテゴリー: js
- 投稿日: 2004-02-26 (木) 20:54:06
メッセージ
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| | ''【closeLastTag.js】
var QUIET_MODE = false;
var REGX_ALL = "</?[\\w\\d]+\\b(.*/>)?|<!--|-->";
var NO_CLOSETAG = "|area|base|basefont|bgsound|br|col|embed|frame" +
"|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);
}
}
|
|
|