all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Patch: default CSS class for SVG images in HTML export
@ 2016-07-25  5:48 Jarmo Hurri
  2016-07-25  9:28 ` Christian Moe
  2016-07-25  9:37 ` Nicolas Goaziou
  0 siblings, 2 replies; 7+ messages in thread
From: Jarmo Hurri @ 2016-07-25  5:48 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 808 bytes --]


Greetings.

The attached patch
- adds a default CSS class org-svg to SVG images embedded in exported
  HTML if no other class is set for the image using attr_html
- documents the existence of this class.

The second attachment is an org-file that can be used to verify that the
patch works as expected. I have tested that it works in Safari, Firefox
and Chrome (Chromium).

If this patch is ok, then what is missing are the default CSS settings
for the new class org-svg in constant org-html-style-default. I simply
did not know what to put there. The manual says that this constant has
basic settings for _all_ defined CSS entities. Either defaults need to
be set for the new class, or the text in the manual needs to be
changed. Or we have to accept that the manual is not logically
coherent. :-)

Jarmo


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 2410 bytes --]

From 087dd280932867b2820f1b87ff2535732615b920 Mon Sep 17 00:00:00 2001
From: Jarmo Hurri <jarmo.hurri@iki.fi>
Date: Mon, 25 Jul 2016 08:25:58 +0300
Subject: [PATCH] lisp/ox-html.el: Provide a default CSS class for embedded SVG
 images

* lisp/ox-html.el (org-html--svg-image): Set CSS class of embedded SVG
images to be org-svg if no other class is set in attributes.

* doc/org.texi (CSS support): Documentation of default CSS class
org-svg for SVG images embedded into exported HTML.
---
 doc/org.texi    |  1 +
 lisp/ox-html.el | 16 ++++++++++++----
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 1c3868c..75f5eac 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -11750,6 +11750,7 @@ div.footnotes       @r{footnote section headline}
 p.footnote          @r{footnote definition paragraph, containing a footnote}
 .footref            @r{a footnote reference number (always a <sup>)}
 .footnum            @r{footnote number in footnote definition (always <sup>)}
+.org-svg            @r{default class for a linked SVG image}
 @end example
 
 @vindex org-html-style-default
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index ce4694d..79ac7e8 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -1629,16 +1629,24 @@ a communication channel."
 
 (defun org-html--svg-image (source attributes info)
   "Return \"object\" appropriate for embedding svg file SOURCE
-with assoicated ATTRIBUTES. INFO is a plist used as a
+with associated ATTRIBUTES. INFO is a plist used as a
 communication channel.
 
 The special attribute \"fallback\" can be used to specify a fallback
-image file to use if the object embedding is not supported."
+image file to use if the object embedding is not supported.
+
+CSS class \"org-svg\" is assigned as the class of the object
+unless a different class is specified with an attribute."
   (let ((fallback (plist-get attributes :fallback))
+	(css-class (plist-get attributes :class))
 	(attrs (org-html--make-attribute-string
 		(plist-put attributes :fallback nil))))
-  (format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
-	  source attrs
+  (format "<object type=\"image/svg+xml\" data=\"%s\" %s %s>\n%s</object>"
+	  source
+	  attrs
+	  (if css-class
+	      ""
+	    "class=\"org-svg\"")
 	  (if fallback
 	      (org-html-close-tag
 	       "img" (format "src=\"%s\" %s" fallback attrs) info)
-- 
2.4.11


[-- Attachment #3: test file --]
[-- Type: text/plain, Size: 429 bytes --]

#+HTML_HEAD_EXTRA: <style> .org-svg { width: 20vw; } .my-svg-class { width: 30vw; } </style>

* styling with default class
  #+BEGIN_SRC asymptote :file svg-image.svg
    size (1cm, 0);
    fill (unitsquare, red);
  #+END_SRC

  #+RESULTS:
  [[file:svg-image.svg]]

* styling with class specified with attribute

  #+ATTR_HTML: :class my-svg-class
  [[file:svg-image.svg]]

* going back to default class
  [[file:svg-image.svg]]

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-07-26  8:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-25  5:48 Patch: default CSS class for SVG images in HTML export Jarmo Hurri
2016-07-25  9:28 ` Christian Moe
2016-07-25  9:37 ` Nicolas Goaziou
2016-07-25 18:34   ` Jarmo Hurri
2016-07-25 20:36     ` Nicolas Goaziou
2016-07-26  8:21       ` Jarmo Hurri
2016-07-26  8:39         ` Nicolas Goaziou

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.