I wrote an add-on Copy as Org-Mode for Firefox which can do this in browser directly (copying the rich HTML directly, instead of copying the raw HTML code), it even can handle HTML tables into Org-mode format.
I found a solution:
(defvar is-latex (org-export-derived-backend-p org-export-current-backend 'latex))
#+BEGIN_SRC latex :file (unless is-latex "myfile.svg") :imagemagick (not is-latex) :results (if is-latex "latex" "graphics file")
This works in a sample file I made (gist), but:
It does not include the packages provided in ...
If you don't need any entitites, then you can customize (i.e. include/exclude) the export of entities via the org-export-with-entities variable.
To set the variable per buffer, you can include the OPTIONS keyword with the value e:nil at the beginning of your file/buffer.
source: https://orgmode.org/manual/Export-Settings.html (and the ...
You can do this with the advice method. It's not the info parameter you need, but src-block. Use the org-export-read-attribute to extract the #ATTR_HTML contents.
The following advice checks for the :class and :id keywords in a #attr_html line and constructs a div around the source block accordingly.
(defun my-org-html-src-block-advice (oldfun src-block ...