emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] ox-html.el: add option to embed SVG for CSS support in SVG


From: gerard . vermeulen
Subject: Re: [PATCH] ox-html.el: add option to embed SVG for CSS support in SVG
Date: Tue, 06 Jun 2023 12:58:15 +0000



On 06.06.2023 09:49, Ihor Radchenko wrote:
gerard.vermeulen@posteo.net writes:

I have been trying to export SVG images having links to CSS from Org to
HTML
and I have found that the this CSS is not active in Firefox (only
browser I tried).

I have found that the CCS is only active under two conditions:
1. The HTML page should manage the CSS that the SVG image links to.
2. The SVG image should be embedded in the HTML page.

CCing Timothy, the maintainer.

Also, does the above mean that Firefox does not support custom CSS user
stylesheets? What am I missing?

No, it means that custom CSS inside a linked SVG image is shielded from
the page that has the link to the SVG image.

To me it looks a natural defense against linking to different SVG images
linking to conflicting custom CSS.

If the HTML page linking to those images should manage the conflicting
custom CSS, the creator of the page is responsible for resolving the conflicts.

I wrote an ox-html derived export backend to embed SVG images:
https://forge.chapril.org/gav451/emacs.d/src/branch/main/site-lisp/ox-my-html/ox-my-html.el
and merged the SVG embedding functionality into ox-html.el leading to
the
attached patch.

Thanks! I will provide high-level comments from general ox.el
perspective.

+    (:html-embed-svg-excludes "HTML_EMBED_SVG_EXCLUDES" nil
+                              org-html-embed-svg-excludes split)
+    (:html-embed-svg-includes "HTML_EMBED_SVG_INCLUDES" nil
+                              org-html-embed-svg-includes split)

This is awkward. To do per-image export adjustments, we usually use
export attributes (#+ATTR_HTML: ...). And why "split"?

I do not think that #+ATTR_HTML allows to embed (= copy) the contents
of an SVG file directly into the HTML page. As far as I understand, it adds
only attributes to HTML elements.

The "split" is because of similarity with :select_tags and :exclude_tags in ox.
It allows several files to be included in or excluded from embedding.

I agree that an attribute like #+EMBED_SVG is less awkward.


+ (:with-html-svg-embedding nil "html-embed-svg" org-html-embed-svg)

We have :html-inline-images. Maybe better :html-embed-svg ?

I agree (the patch started as an derived backend with ox-beamer as an
example where those kind of variables are prefixed with :with; this is
a left-over).

+(defcustom org-html-embed-svg nil
...
+  :version "30.0"

We do not use :version tag. Please use :package-version.
See Elisp manual section "15.1 Common Item Keywords".

My fault.

Also, maybe instead of t/nil boolean values here, we may allow the value
to be a list of regular expressions or a string representing regular
expression. This will allow what you are trying to do with
HTML_EMBED_SVG_INCLUDES. The list elements might also be (not "..."),
replicating HTML_EMBED_SVG_EXLCUDES.

Even more generally, we may turn this into HTML_EMBED_IMAGES and embed
all the images (possibly filtered by regexp). This will be slightly
beyond the scope of this patch though.

+(defun org-html--embed-svg-p (link path info)
+ "Check whether LINK and INFO specify to embed the SVG file named PATH.
+LINK must have no contents and link to an SVG file.  INFO may contain
+lists of SVG files to include in and/or to exclude from embedding."
+  (and (not (org-element-contents link))

Please use `org-export-inline-image-p'.

I think that the terminology "inline-image" in ox-html is confusing.
In ox-html the result of the "inline-image"  code is an HTML tag like

<img with attributes inside>

It does not mean that image data is copied inline as with embedding.

+(defun org-html-svg-contents (path)
+  "Return the SVG contents of the file named PATH."
+  (with-temp-buffer
+    (insert-file-contents path)
+ ;; Delete text preceding something starting as an SVG root element.
+    ;; The intent is to remove XML declarations (and XML comments).
+ ;; This breaks in case of a preceding XML comment with <svg inside
+    ;; or a preceding XML element with an SVG element inside.
+ ;; See https://emacs.stackexchange.com/a/57433 for the original code.

But the original code is different, no?

Yes, I pretend that my code is an improvement:
1. The with-syntax-table is superfluous.
2. The error message gives a reason and the filename causing it.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]