Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は Trac のプラグインに取り組んでおり、Genshi ストリームを操作してレンダリングされた HTML に JavaScript を挿入しています。
JavaScript 関数が既に HTML に含まれているかどうかをテストする必要があります。そうでない場合は新しいバージョンで上書きし、そうでない場合は HTML に追加します。
関数が既に存在するかどうかを確認するために検索を実行するにはどうすればよいですか?
あはは!! 最初にストリームから関数を削除しようとすることで、これを解決しました。
stream = stream | Transformer('.//head/script["functionName()"]').remove()
そして、更新された/新しいバージョンを追加します:
stream = stream | Transformer('.//head').append(tag.script(functionNameCode, type="text/javascript"))