From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jarmo Hurri Subject: Re: Patch: default CSS class for SVG images in HTML export Date: Mon, 25 Jul 2016 21:34:06 +0300 Message-ID: <87fuqxo9cx.fsf@iki.fi> References: <87h9bep8s4.fsf@iki.fi> <87eg6ivz0u.fsf@saiph.selenimh> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bRki5-0005ZU-1h for emacs-orgmode@gnu.org; Mon, 25 Jul 2016 14:34:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bRkhz-0002ex-RI for emacs-orgmode@gnu.org; Mon, 25 Jul 2016 14:34:36 -0400 Received: from plane.gmane.org ([80.91.229.3]:54775) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bRkhz-0002ep-Fj for emacs-orgmode@gnu.org; Mon, 25 Jul 2016 14:34:31 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1bRkhx-00023Y-VO for emacs-orgmode@gnu.org; Mon, 25 Jul 2016 20:34:30 +0200 Received: from 82-181-168-52.bb.dnainternet.fi ([82.181.168.52]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 Jul 2016 20:34:29 +0200 Received: from jarmo.hurri by 82-181-168-52.bb.dnainternet.fi with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 25 Jul 2016 20:34:29 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Ok, here is trial number 2, with patch and test files. The test file shows multiple use cases. Just let me know if something in this still needs fixing. Jarmo PS. org-combine-plists is a cool function PPS. I just amended the commit of my first trial, that's why the timestamp is still from this morning. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ox-html.el-Provide-a-default-CSS-class-for-embe.patch Content-Description: patch >From 0cb1fd2f3507c7d5db060ba62711896698a5f67c Mon Sep 17 00:00:00 2001 From: Jarmo Hurri 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. org-html-style-default: Provide default properties for new CSS class. * 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 | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 1c3868c..68b3c69 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 )} .footnum @r{footnote number in footnote definition (always )} +.org-svg @r{default class for a linked @file{.svg} image} @end example @vindex org-html-style-default diff --git a/lisp/ox-html.el b/lisp/ox-html.el index ce4694d..456a236 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -440,6 +440,7 @@ for the JavaScript code in this tag. { font-size: 10px; font-weight: bold; white-space: nowrap; } .org-info-js_search-highlight { background-color: #ffff00; color: #000000; font-weight: bold; } + .org-svg { width: 90%; } /*]]>*/--> " "The default style specification for exported HTML files. @@ -1628,21 +1629,27 @@ a communication channel." info))) (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 -communication channel. + "Return \"object\" embedding svg file SOURCE with given 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." +The special attribute \"fallback\" can be used to specify a +fallback 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)) (attrs (org-html--make-attribute-string - (plist-put attributes :fallback nil)))) - (format "\n%s" - source attrs - (if fallback - (org-html-close-tag - "img" (format "src=\"%s\" %s" fallback attrs) info) - "Sorry, your browser does not support SVG.")))) + (org-combine-plists + ;; Remove fallback attribute, which is not meant to + ;; appear directly in the attributes string, and + ;; provide a default class if none is set. + '(:class "org-svg") attributes '(:fallback nil))))) + (format "\n%s" + source + attrs + (if fallback + (org-html-close-tag + "img" (format "src=\"%s\" %s" fallback attrs) info) + "Sorry, your browser does not support SVG.")))) (defun org-html--textarea-block (element) "Transcode ELEMENT into a textarea block. -- 2.4.11 --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=svg-class-test.org Content-Description: test #+HTML_HEAD_EXTRA: * 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]] * case where class id nil (no CSS class) #+ATTR_HTML: :class nil [[file:svg-image.svg]] --=-=-=--