Thread:Extension talk:WYSIWYG/Event fired when switching to/from wikitext view ?

I'm trying to make a find & replace function that applies automatically when switching to/from wikitext view.

I tried to use "addRules". That works only partially. For example I can replace some text among the plain text. But, at the time this function is processed, the wikitext is already transformed into HTML. So, for example, templates are no more under the form but under a complicated. So it is far more difficult to handle them at that time.

I'd like to trigger a regexp before wikitext is transformed to HTML, but I can't find the events that correspond to. I tried the events toHtml, toDataFormat, setData... but in vain. Any idea ?