The issue was solving by choosing the second approach. Instead of generating a XWiki verbatim, we generate a group having the class "code". Doing this we produce a result similar to the one you get by rendering the confluence syntax.