// // Footnote.mac (2006/09/30) // by IKKI http://www18.big.or.jp/~fujiwara/ikki/ // // 2006/09/20 v1.0 初版 // 2006/10/01 v1.1 {notag} = HTMLタグ除去 // $Mark と $Body では次の変数が有効 // // {m} = 節番号(出力位置ごとにインクリメント) // {n} = 脚注番号(脚注1件ずつインクリメント、出力位置ごとにリセット) // {text} = 脚注の内容 // {notag} = 脚注の内容(HTMLタグを除去) // 脚注記号 $Mark = "*{n}"; // 脚注本体 $Head = "\n
\n"; $Body = "\t
*{n}
\n\t
{text}
\n"; $Tail = "
\n"; // コメント識別子(正規表現のメタキャラクタは要エスケープ) $Comb = ""; // 終了 // 本文の例 // //

1節

//

1節の段落1です。

//

1節の段落2です。

// 出力位置 // //

2節

//

2節には脚注がありませんでした。

// 出力位置 // //

3節

//

3節の段落1です。

//

3節では foottext を書き忘れてしまいました。

call Initialize; call Main; call Finalize; endmacro; Main: #ox = x; #oy = y; #m = 1; #n = 0; gofiletop; while (true) { call Find "footnote|foottext"; // message $$return; $$key = leftstr($$return, strstr($$return, "|")); if ($$key == "") $$key = $$return; $$val = midstr($$return, strlen($$key) + 1, 8192); if ($$key == "footnote") { #n = #n + 1; $text[#n] = $$val; call Mark; } else if ($$key == "foottext") { call Dump; #m = #m + 1; #n = 0; } else { break; } } gofileend; call Dump; if (##return) moveto #ox, #oy; return; Find: // $$1 = キー(正規表現可) // $$return = "キー|値" // 実行後の選択範囲 = で囲まれた部分 escape; searchdown "(?<=" + $Comb + "\\{)(" + $$1 + ")(\\||" + $Comd + ")", regular; if (!result) return ""; ##x1 = foundtopx; ##y1 = foundtopy; escape; searchdown $Comd, regular; if (!result) return ""; ##x2 = foundtopx; ##y2 = foundtopy; ##x3 = foundendx; ##y3 = foundendy; $$value = gettext(##x1, ##y1, ##x2, ##y2); escape; searchdown $Comb + "\\}" + $Comd, regular; if (!result) return ""; escape; beginsel; moveto ##x3, ##y3; endsel; return $$value; Mark: if (selecting) delete; $$item = $Mark; call GSUBR $text[#n], "<.*?>", ""; $$notag = $$return; call GSUBR $$item, "\\{m\\}", str(#m); $$item = $$return; call GSUBR $$item, "\\{n\\}", str(#n); $$item = $$return; call GSUBR $$item, "\\{text\\}", $text[#n]; $$item = $$return; call GSUBR $$item, "\\{notag\\}", $$notag; $$item = $$return; insert $$item; return; Dump: if (selecting) delete; if (#n < 1) return true; insert $Head; ##i = 1; while (##i <= #n) { $$item = $Body; call GSUBR $text[##i], "<.*?>", ""; $$notag = $$return; call GSUBR $$item, "\\{m\\}", str(#m); $$item = $$return; call GSUBR $$item, "\\{n\\}", str(##i); $$item = $$return; call GSUBR $$item, "\\{text\\}", $text[##i]; $$item = $$return; call GSUBR $$item, "\\{notag\\}", $$notag; $$item = $$return; insert $$item; ##i = ##i + 1; } insert $Tail; return false; GSUBR: // HmJre.dll による正規表現置換 // $$1 = 対象文字列 // $$2 = 検索パターン // $$3 = 置換文字列(後方参照不可) // ##4 = 1:大文字小文字を区別する $$f = leftstr("FindRegularNoCaseSense", 11 + (##4 == 0) * 11); $$s = $$1; while (true) { ##p = dllfunc($$f, $$2, $$s, 0); if (##p < 0) break; $$r = $$r + leftstr($$s, ##p) + $$3; $$s = midstr($$s, ##p + dllfunc("GetLastMatchLength"), 8192); } if (##p == -2) message "正規表現のエラーです\n" + $$2; return $$r + $$s; Initialize: loaddll "HmJre.dll"; if (!result) { message "HmJre.dll がロードできません。秀丸エディタ v6.00 以上をインストールしてください。"; endmacro; } setcompatiblemode 0x0200; $searchbuffer = searchbuffer; #searchoption = searchoption; disabledraw; return true; Finalize: enabledraw; setsearch $searchbuffer, #searchoption; freedll; return;