Note that works only if the attachments is accessible under that token. The day that the token is invalidated, the attachment will not be reachable, so this is not really a solution.
Implementation
It is easy to replace the !(<filename>) into !<filenname>! by using following construct
Line 1 uses the mergeComments to iterate over all the comments in the replica and summons the closure to be run.
Line 4 calls the replaceAll groovy string method. For each string segment matching the regexp a replacement is created. The replacement contains the necessary code to show the image with a maximum width of 512.