Is it possible? It would be very useful. Maybe a more general solution is possible? When preview plugin takes a text being edited, sends it to some command pre-specified, and displays an output from that command in the preview area. Different commands may be specified for various file extensions of MIME types.
It is possible, needs the KGraphViewer KParts plugin installed (I only know about this one). See example screenshot at https://frinring.wordpress.com/2017/09/25/ktexteditorpreviewplugin-0-1-0/ for editing Dot files in action :) I agree with your proposed approach of a more general solution. Actually, the preview plugin actually does it: any actual rendering is delegated to other plugins, based on the MIME type, and does so by reusing the existing KParts plugin infrastructure. The preview plugin itself just takes a snapshot of the current text and sends it over to the KParts plugin, any rendering and further UI is completely controlled by those KParts plugins.
I've installed KGraphViewer, and now it works like a charm. Thank you very much!