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

Support GitHub-like absolute /path/to/image #8272

Open
ctjlewis opened this issue Sep 2, 2022 · 4 comments
Open

Support GitHub-like absolute /path/to/image #8272

ctjlewis opened this issue Sep 2, 2022 · 4 comments

Comments

@ctjlewis
Copy link

ctjlewis commented Sep 2, 2022

In a GitHub README, we reference images like:

![](/assets/images/image.png)

Where the absolute filepath is actually resolved while treating cwd as the root. GitHub resolves paths this way because it's analogous to parking the project on a server, where /assets/... would correctly reference the file in question.

Request: Support GitHub-like absolute paths

It is not sensible to change the default behavior, and Pandoc should probably treat absolute filepaths the way it currently does out of the box. But it would be appropriate to have a --github-absolute-paths flag or something similar to tell Pandoc that /path/to/file actually means ./path/to/file with respect to cwd, i.e. ${pwd}/path/to/file.

Current workaround is to manually replace /assets/... with assets/... (relative), run Pandoc, and then swap back so GitHub can display the images correctly.

Related Issues

@ctjlewis
Copy link
Author

ctjlewis commented Sep 5, 2022

@tarleb - Tried -f markdown+rebase_relative_paths but was unable to workaround. Thanks for looking at this issue!

@jgm
Copy link
Owner

jgm commented Sep 5, 2022

OK, right, rebase_relative_paths is only for relative paths, and these are absolute.

I'm not sure what the best solution is. --github-absolute-paths seems a bit clunky; maybe something like --resource-root=$(pwd)?

In the mean time, an easy workaround would be a Lua filter that matches Image elements with absolute paths and removes the leading /.

@tarleb
Copy link
Collaborator

tarleb commented Sep 5, 2022

function Image (img)
  img.src = pandoc.path.make_relative(img.src, '/')
  return img
end

May require 2.19.2 due to a bug in make_relative in earlier versions.

@dreamos82
Copy link

I tried the above solution with pandoc version 2.17.1.1 and apparently it worked.

Btw for completion of information (hoping to be helpful to other pandoc beginners like me) the lua script above, must be saved as it is into a file (i.e. makerelativepaths.lua) and pandoc must be launched with the following parameter:

pandoc ... --lua-filter makerelativepaths.lua

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

No branches or pull requests

4 participants