-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Image files in markdown using relative paths not found converting to docx #3342
Comments
That's an absolute path, not a relative path (though it's a relative URI). Pandoc will look for that file at |
You could use a program acting on pandoc's internal AST instead of doing a manual search/replace operation if you'd like to automate the post-processing of your document: Panflute is a nice and very complete library for this. There is also my small but experimental panlunatic writer, which relies on pandoc's internal lua interpreter to do some light-weight editing. Below is a script that would turn absolute image paths into relative image paths. -- Make image paths relative by removing any leading slash.
--
-- Save into relimg.lua and make sure `panlunatic.lua` and `dkjson.lua` are in the same dir.
-- Invoke with:
-- pandoc -t relimg.lua [READER-OPTIONS] | pandoc -f json [WRITER-OPTIONS]
panlunatic = require("panlunatic")
setmetatable(_G, {__index = panlunatic})
function Image(s, src, tit, attr)
return panlunatic.Image(s, src:gsub("^/", ""), tit, attr)
end |
This is pretty nice.
I feel like what we really need are StackValue instances
that map pandoc types directly to lua types, and back.
Then we could have lua AST transformations that didn't
need to go through intermediate JSON. This could all
be built in, so a few lines of lua could serve as a filter
without any dependencies.
This would also allow us to provide a library that would
make it possible to write custom parsers in lua that produce
a Pandoc AST.
…panlunatic = require("panlunatic")
setmetatable(_G, {__index = panlunatic})
function Image(s, src, tit, attr)
return panlunatic.Image(s, src:gsub("^/", ""), tit, attr)
end
—
You are receiving this because you commented.
Reply to this email directly, [3]view it on GitHub, or [4]mute the
thread.
References
1. http://scorreia.com/software/panflute/
2. https://github.com/tarleb/panlunatic
3. #3342 (comment)
4. https://github.com/notifications/unsubscribe-auth/AAAL5KYOWY1sLG_B_Ho1JdAAErkDInN0ks5rQKcigaJpZM4Ldl64
|
My plan was to:
I'm still getting used to the lua-way of doing things, progress is slow. |
Sounds like a good plan!
+++ Albert Krewinkel [Jan 08 17 03:46 ]:
… My plan was to:
1. enable simple filtering via the custom-writer hack (mostly done);
2. write a true filtering library in lua (in progress, not much to
show yet);
3. use the library abstractions as the basis for StackValue instances;
4. integrate library.
I'm still getting used to the lua-way of doing things, progress is
slow.
—
You are receiving this because you commented.
Reply to this email directly, [1]view it on GitHub, or [2]mute the
thread.
References
1. #3342 (comment)
2. https://github.com/notifications/unsubscribe-auth/AAAL5MFY6Ec7bcDqlQi9kqxBrZVi1M46ks5rQMx4gaJpZM4Ldl64
|
Anyway, closing this issue -- it does not seem to be a bug, and a workaround has been provided. |
I had a similar issue while trying to implement the Pandoc PDF exportation method in Grafoscopio, with a lot of relative images not found. The solution was to include a command to move to the directory where local routes are defined, before running the Pandoc exportation command. If useful, here is the Pharo/Smalltalk code that makes this is this: pandocCommand := 'cd ', self markdownFile parent fullName,'; ',
'pandoc ', self pandocOptionsComputed, ' ',
self markdownFile fullName, ' -o ', self pdfFile.
ExternalUnixOSProcess command: pandocCommand. where |
pandoc version:
Command being used:
I have tested converting my post to a docx file with the image paths shown both in markdown style and HTML (using the
img
tag). I have to use a relative path for referencing images in my post based on where I have the site hosted (GitHub pages), and that requires that I have a leading backslash:The above will generate the below error:
However an interesting thing is the HTML tag with the same relative path, pandoc does not spit out the warning, but still does not include the image in the docx file.
When I try to convert a given md file with pandoc it cannot find the images unless I remove that leading backslash. As soon as I update the image references to the below line the docx file is generated successfully with images included as expected:
Does a flag exist for pandoc where I wouldn't have to remove the leading backslash or is this just the way it works?
NOTE: I don't mind having to do that as a work around (just a quick find/replace), just curious to know why it cannot handle it.
The text was updated successfully, but these errors were encountered: