pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
602 stars 165 forks source link

include-files sub file can not use URL image? #194

Open ajeep8 opened 2 years ago

ajeep8 commented 2 years ago

main.md

This is main.md

```{.include}
sub.md
```

sub.md

This is sub.md

![remote image](https://upload.wikimedia.org/wikipedia/commons/4/48/Markdown-mark.svg)

![local image](Markdown-mark.svg)

pandoc -L include-files.lua sub.md -o sub.pdf

It's OK.


pandoc -L include-files main.md -o main.pdf

[WARNING] Could not fetch resource https:/upload.wikimedia.org/wikipedia/commons/4/48/Markdown-mark.svg: InvalidUrlException "https:/upload.wikimedia.org/wikipedia/commons/4/48/Markdown-mark.svg" "URL must be absolute" Replacing image with description.

the local image is OK, but the remote image not.

ajeep8 commented 2 years ago

https:/upload one '/' less, why?

ajeep8 commented 2 years ago

I think it's because consider URL as relative path

    -- If image paths are relative then prepend include file path
    Image = function (image)
      if (string.sub(image.src,1,7) ~= "http://") and (string.sub(image.src,1,8) ~= "https://") then
        if path.is_relative(image.src) then
          image.src = path.normalize(path.join({include_path, image.src}))
        end
      end
      return image
    end,
alerque commented 2 years ago

Did you ever figure this out?