Question

I'm working on a plugin for Trac and am inserting some javascript into the rendered HTML by manipulating the Genshi stream.

I need to test if a javascript function is already in the HTML and if it is then overwrite it with a new version, if it isn't then add it to the HTML.

How do I perform a search to see if the function is already there?

Was it helpful?

Solution

Aha!! I have solved this by first attempting to remove the function from the stream:

stream = stream | Transformer('.//head/script["functionName()"]').remove()

and then adding the updated/new version:

stream = stream | Transformer('.//head').append(tag.script(functionNameCode, type="text/javascript"))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top