emacs-orgmode
[Top][All Lists]
Advanced

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

possible fix for a bug in org-mode html export


From: bpanthi
Subject: possible fix for a bug in org-mode html export
Date: Wed, 6 May 2020 21:14:14 +0545
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

When exporting an org file containing latex fragments with option

#+OPTIONS: tex:dvipng 

in the html file the png image src attribute's value is not a valid URI. <img src="" ...>  while it should be <img src="" class="moz-txt-link-rfc2396E" href="file:///e:/dir/sth.png">"file:///e:/dir/sth.png" ...>  for the browser to work. In my config I have  (setq org-preview-latex-image-directory "E:/tmp/ltximg/") so that all images are created in a single directory and don't clutter my org file directory.

I fixed this issue for me by modifying `org-html--format-image' function of ox-html.el file as follow:

(defun org-html--format-image (source attributes info)
  "Return \"img\" tag with given SOURCE and ATTRIBUTES.
SOURCE is a string specifying the location of the image.
ATTRIBUTES is a plist, as returned by
`org-export-read-attribute'.  INFO is a plist used as
a communication channel."
  (if (string= "svg" (file-name-extension source))
      (org-html--svg-image source attributes info)
    (org-html-close-tag
     "img"
     (org-html--make-attribute-string
      (org-combine-plists
       (list :src (concat "file:///" source)
	     :alt (if (string-match-p "^ltxpng/" source)
		      (org-html-encode-plain-text
		       (org-find-text-property-in-string 'org-latex-src source))
		    (file-name-nondirectory source)))
       attributes))
     info)))

I just changed (list :src source ...) to (list :src (concat "file:///" source).

I don't know if it is an acceptable way or it further causes bugs in other places.
Hope that this will find the proper way and fix it. 

(emacs-version) = "GNU Emacs 26.3 (build 1, x86_64-w64-mingw32) of 2019-11-01"
(org-version) = "9.3.6"

Emacs Admirer,
Bibek Panthi

Attachment: sample.org
Description: Text document


reply via email to

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