Custom mimetype & transform for regular Page

I am developing an add-on for including a rendered blockdiag (SVG) diagram on a regular Plone page.

For that, I thought the simplest would be to register a custom mime type & develop a transform for it. So that the user can then simply add a regular Page, select the mime type & write the diagram using blockdiag syntax, and let the transform produce SVG that will be embedded within the page HTML.

But I am not sure whether I should write a "traditional" portal transform or an implementation of plone.app.textfield "ITransformer" (which seems simpler). Could either be used, somehow?

Thoughts? Apparently, unless explicitly specified, the mime types configured via/@@markup-controlpanel are enabled for user to choose from. Those are in turn provided by a vocabulary (AllowableContentTypes in plone.app.vocabularies).

Update: I created a portal transform and registered it (for anyone interested in how to develop a portal transform, see Products.PortalTransform @ github for docs on the interface).

My transform is registered correctly (as per portal_transforms ZMI), from my custom mime type text/x-blockdiag to html (tried both regular and the 'safe' HTML mime type used by Plone). Also tried 'application/xml+svg'.

Regardless of what I set the output mime type to in the transform, it for some reason gets called twice - and the second time, the input fed to it by PortalTransforms is the output of the previous run (SVG). Which of course fails. Why is the transform called again?

I've taken a look at a number of other transforms out there, and none of them indicates they expect to be called again with their own output as input.

Is there something I've missed?

I have developed a couple of transforms - often with the need to debug the result. But, I never have observed that a transform was fed its own output. I suggest to debug the transform (e.g. by putting a temporary programmatic breakpoint into your transform code ("import pdb; pdb.set_trace()")). This should allow you to locate the logic that causes the second activation.

Yes, been doing some of that. Upon going deeper, it turns out that I may have uncovered a bug in plone.app.contenttypes.

When a regular Page (with non-HTML source content) is saved, the SearchableText indexer accesses the source content first (and transforms it). Transforms are then run again to get the HTML output of the page.

What happens is that first, SearchableText indexer (from plone.app.contenttypes) triggers on-demand transform by passing transformed rich text value to portal transforms, to get the plaintext value, but with the wrong (mismatching) mime type (that of the raw non-transformed rich text value). Which results in the transform being passed its own dogfood when transformation to plaintext is run (second transform). Which in my case fails and the process never gets to the point where transforms are run to get the rendered HTML page output.

If I understood everything correctly. I do not see how the mismatch could be intentional.

I tried monkeypatching plone.app.contenttypes as per my bug report suggestion and everything seems to work fine after that. My transform starts working and other transforms keep working ok as well.

What I don't understand is why Plone seems to insist on running the safe html transform when my transform is already registered as producer of x-html-safe output (to prevent further transforms from taking place).