-
Hi, When converting a Markdown document into something like a DOCX one, I would like the original file names and file paths to be preserved. This would be useful to relink to alternative versions of the images, or to update them. It would also be useful when importing the DOCX file into a page layout program, where the links can be then rebuilt with a simple command. In other words, I would like that something like this:
remains 'my-beautiful-paysage.jpg' in Word, with the link pointing to an 'image' folder in the same directory as the generated DOCX file. Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Try this filter (I have not tested it): return {
{
Image = function(image)
local filename = pandoc.path.filename(image.src)
local link_content = pandoc.Str(filename)
local link = pandoc.Link(link_content, image.src, filename)
return link
-- if you want both the Image and the Link use this:
-- return pandoc.List({image, link})
end
}
} save it in a file pandoc -f markdown -t docx -o test.docx -L images_as_links.lua test.md |
Beta Was this translation helpful? Give feedback.
-
Please see #9815 — ODT files can easily preserve the images as links rather than embeds, in fact the opendocument writer that ODT is based on always links images. It should be possible to use opendocument to ODT and have properly linked images. #9815 shows the XML code is simple and so a filter could inject linked figures into ODT directly as a second option. ODT can be converted to DOCX if you must use DOCX. As you mentioned, DOCX's OpenXML uses a much more complex markup for linked images that depends on a separate file, this is more challenging to solve with a filter for DOCX output directly. I imagine this requires direct support from the DOCX writer in Pandoc... |
Beta Was this translation helpful? Give feedback.
Please see #9815 — ODT files can easily preserve the images as links rather than embeds, in fact the opendocument writer that ODT is based on always links images. It should be possible to use opendocument to ODT and have properly linked images. #9815 shows the XML code is simple and so a filter could inject linked figures into ODT directly as a second option. ODT can be converted to DOCX if you must use DOCX.
As you mentioned, DOCX's OpenXML uses a much more complex markup for linked images that depends on a separate file, this is more challenging to solve with a filter for DOCX output directly. I imagine this requires direct support from the DOCX writer in Pandoc...