From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pip Cet Subject: Re: Inline Images Export Bug Date: Wed, 26 Aug 2015 19:39:37 +0000 Message-ID: References: <55DDFCBF.2050202@gmail.com> <876141apq4.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e0158b2cecae540051e3c02f5 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUgXr-0000N6-L6 for emacs-orgmode@gnu.org; Wed, 26 Aug 2015 15:39:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUgXq-0002b6-2K for emacs-orgmode@gnu.org; Wed, 26 Aug 2015 15:39:39 -0400 Received: from mail-ig0-x22b.google.com ([2607:f8b0:4001:c05::22b]:38584) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUgXp-0002b1-QC for emacs-orgmode@gnu.org; Wed, 26 Aug 2015 15:39:37 -0400 Received: by igfj19 with SMTP id j19so20367187igf.1 for ; Wed, 26 Aug 2015 12:39:37 -0700 (PDT) In-Reply-To: <876141apq4.fsf@gmx.us> 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rasmus Cc: emacs-orgmode@gnu.org --089e0158b2cecae540051e3c02f5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I've used interactive SVGs with ox-html output quite a lot, and I found it necessary to add the following horrible code; I'm not sure it's still required: ---- let svgdoc =3D object.contentDocument; let svgid =3D object.id; if (!svgdoc) { if (object.parentNode /* XXX why is this necessary */) object.parentNode.innerHTML =3D ""; return; } let found =3D false; for (let el of svgdoc.getElementsByTagName("svg")) { let width =3D el.getAttribute("width"); let height =3D el.getAttribute("height"); let width_pt =3D width.match(/^([0-9]*)pt$/)[1]; let height_pt =3D height.match(/^([0-9]*)pt$/)[1]; let width_px =3D 5/4 * width_pt; let height_px =3D 5/4 * height_pt; object.setAttribute("width", width_px + "px"); object.setAttribute("height", height_px + "px"); found =3D true; } ---- In my case, the SVG was produced by graphviz, so it always has the width and height attributes. This is a minor issue, but I also think the fallback message ("Sorry, your browser does not support SVG.") is really horrible and misleading. It's very unlikely to be a browser issue today, and much more likely to be a missing file or a user deliberately disabling SVG. In that case, software shouldn't say it's sorry :-) "Cannot load SVG file." would be a better message, I think. On Wed, Aug 26, 2015 at 6:06 PM, Rasmus wrote: > Hi Scott, > > Thanks for your bug report. > > Scott Randby writes: > > > When did Org start using the tag for inline image HTML > > export? > > You should use git-blame to find out if you care. > > > > The problems with the second bit of exported code is that it doesn't > > scale the image to fit the block with 50% width (only a small part of > > the image is visible), and you when you right click on the image, you > > can't view it, save it or anything. > > > > [...] > > > > Clearly, Org 8.3 is not using an tag when exporting SVG images > > to HTML, something which is a major issue for me. It essentially makes > > Org unusable for HTML export. I really would appreciate a fix for this > > bug. > > I'm not sure it's a bug. It's IS clearly a quite complicated issue, e.g.= : > > > http://stackoverflow.com/questions/4476526/do-i-use-img-object-or-embed-f= or-svg-files > > Perhaps it should be configurable, perhaps even as a default and a > per-image basis (via #+attr_html). > > If you can provide a (html) solution that takes into consideration the > issues mentioned on SO that would of course be great. In the age of d3.j= s > interactivity COULD be an issue (I would always load "interactive svgs" > via JS, but I'm a pretty na=C3=AFve svg user so I don't know what's possi= ble). > > Rasmus > > -- > Together we'll stand, divided we'll fall > > > --089e0158b2cecae540051e3c02f5 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I've used interactive SVGs with ox-html output qu= ite a lot, and I found it necessary to add the following horrible code; I&#= 39;m not sure it's still required:

----
=C2=A0=C2=A0=C2=A0 le= t svgdoc =3D object.contentDocument;
=C2=A0=C2=A0=C2=A0 let svgid =3D object.id;

=C2=A0=C2=A0=C2=A0 if (!sv= gdoc) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (object.parentNode= /* XXX why is this necessary */)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 object.parentNode.innerHTML =3D ""= ;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return;
=C2=A0=C2=A0=C2= =A0 }

=C2=A0=C2=A0=C2=A0 let found =3D false;
=C2=A0=C2=A0=C2=A0 = for (let el of svgdoc.getElementsByTagName("svg")) {
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let width =3D el.getAttribute("width= ");
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let height =3D el.ge= tAttribute("height");

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 let width_pt =3D width.match(/^([0-9]*)pt$/)[1];
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 let height_pt =3D height.match(/^([0-9]*)pt$/)[= 1];

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let width_px =3D 5/4 = * width_pt;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 let height_px =3D= 5/4 * height_pt;

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 object.= setAttribute("width", width_px + "px");
=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 object.setAttribute("height", heig= ht_px + "px");
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 foun= d =3D true;
=C2=A0=C2=A0=C2=A0 }
----

In my case, t= he SVG was produced by graphviz, so it always has the width and height attr= ibutes.

This is a minor issue, but I also think the fallb= ack message ("Sorry, your browser does not support SVG.") is real= ly horrible and misleading. It's very unlikely to be a browser issue to= day, and much more likely to be a missing file or a user deliberately disab= ling SVG. In that case, software shouldn't say it's sorry :-)
"Cannot load SVG file." would be a better message, I= think.


On Wed, Aug 26, 2015 at 6:06 PM, Rasmus <rasmus@gmx.us> wrote:
Hi Scott,

Thanks for your bug report.

Scott Randby <srandby@gmail.com= > writes:

> When did Org start using the <object> tag for inline image HTML<= br> > export?

You should use git-blame to find out if you care.


> The problems with the second bit of exported code is that it doesn'= ;t
> scale the image to fit the block with 50% width (only a small part of<= br> > the image is visible), and you when you right click on the image, you<= br> > can't view it, save it or anything.
>
> [...]
>
> Clearly, Org 8.3 is not using an <img> tag when exporting SVG im= ages
> to HTML, something which is a major issue for me. It essentially makes=
> Org unusable for HTML export. I really would appreciate a fix for this=
> bug.

I'm not sure it's a bug.=C2=A0 It's IS clearly a quite c= omplicated issue, e.g.:

=C2=A0 =C2=A0 h= ttp://stackoverflow.com/questions/4476526/do-i-use-img-object-or-embed-for-= svg-files

Perhaps it should be configurable, perhaps even as a default and a
per-image basis (via #+attr_html).

If you can provide a (html) solution that takes into consideration the
issues mentioned on SO that would of course be great.=C2=A0 In the age of d= 3.js
interactivity COULD be an issue (I would always load "interactive svgs= "
via JS, but I'm a pretty na=C3=AFve svg user so I don't know what&#= 39;s possible).

Rasmus

--
Together we'll stand, divided we'll fall



--089e0158b2cecae540051e3c02f5--