Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems adding image caption #355

Open
dalanicolai opened this issue Oct 3, 2020 · 1 comment
Open

Problems adding image caption #355

dalanicolai opened this issue Oct 3, 2020 · 1 comment

Comments

@dalanicolai
Copy link

dalanicolai commented Oct 3, 2020

I would like the plugin to also parse the caption of an image, like when using org-html-export-as-html, so that the relative path for the image folder is ../images for the source as well as for the output files. Now when I use the syntax [[../images/file.png]] and export the function org-html-export-as-html then img src tag contains the correct path:

<img src="../images/meditate.png" alt="meditate.png" />

However when building with Nikola then for some reason the ../ in the image path is removed:

<img src="images/meditate.png" alt="nil">

Now from the first answer here I tried to add the ../ back using:

(defun my-custom-figsource (contents backend info)
  (when (eq backend 'html)
    (replace-regexp-in-string "src=\""
                              "src=\"../" contents)))

(add-to-list 'org-export-filter-final-output-functions #'my-custom-figsource)

(this just replaces the the src=" with src="../). However now when building with Nikola I get a double ../../ in the image path.

I guess my question is, why the ../ is removed when building with Nikola?

If this would work, then I guess also the file and img-url links types here could just be removed, and the info replaced with the correct info, i.e. just use a relative path instead of the nikola style path [[/images/file.png]] which gets resolved as an absolute path. I am happy to take care of that, as soon as I find out why the ../ is getting removed by the Nikola build.

@dalanicolai
Copy link
Author

Okay, I am still wondering how it all works exactly, but I was able to get what I want by adding the following lines to init.el:

(defun my-custom-figsource (contents backend info)
  (when (eq backend 'html)
    (replace-regexp-in-string "src=\"/"
                              "src=\"" contents)))

(add-to-list 'org-export-filter-final-output-functions #'my-custom-figsource)

So now I just use a relative link incl. caption like this:

#+CAPTION: caption text
#+NAME: fig_name
[[../images/file.png]]

and now the image paths in the img src tags in both the blog its index.html and the post its index.html are correct.

Actually with this solution I am not really sure what useful feature the img-url and file link types add.

Maybe I should replace them and the instructions with this solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant