jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.65k stars 3.38k forks source link

Markdown to EPUB: images (path separator issue) #9695

Open Darthagnon opened 6 months ago

Darthagnon commented 6 months ago

Explain the problem.

I'm compiling an EPUB from Markdown source files, one file per chapter. I'm compiling the book using the following command in a batch file:

pandoc --toc --toc-depth=3 --metadata-file=metadata-file.yaml --epub-cover-image=Images/cover.jpg --css=stylesheet.css -o "Ishtar's Odyssey.epub" 03_A_Mission.md 04_Truant.md 05_The_Caravan.md 06_Error_of_Judgment.md 07_The_Substitute.md 08_Peril.md 09_The_Debate.md 10_Enemies.md 11_Outpost.md 12_Birthday_Surprise.md
rem LIST INCOMPLETE CHAPTERS HERE: 13_Attack.md 14_The_Law.md 15_Two_Rivers.md 16_Desert.md 17_Friends.md 18_Jothams Journey.md 19_Decha_of_Megiddo.md 20_Courage.md 21_Tabithas_Travels.md 22_Special_Instructions.md 23_Ishtars_Odyssey.md 24_Messiah.md 25_Advent_Thru_Time.md
pause

Some of the chapters reference images, e.g.

![](Images/p19_screenshot.png) 

The images exist, but are ignored by Pandoc and are not included in the rendered EPUB. Except for the cover, which is included. How can I make sure they're included?

Pandoc version?

What version of pandoc are you using, on what OS? v3.1.13 amd64 Win10 v1709

Possibly related issues:

Some of the above issue threads seem to suggest referencing the images in ways not standard to Markdown in order to force Pandoc to include them. Surely there's a better, simpler way? Any advice would be appreciated!

jgm commented 6 months ago

This should work! I just did a small test and it worked fine. You'll have to provide a complete test case we can run to duplicate the issue. (Not your whole book -- just pare things down to the minimum necessary to reproduce it, and give us all the files necessary.)

jgm commented 6 months ago

I see you're on Windows. It's possible that the problem involves / as a path separator? Does the image appear if you use \ instead of / in the image path?

Darthagnon commented 6 months ago

Aha, that's it. When I use backslashes for image paths, it works. Thank you!

Any chance slash translation could be added as a feature? The Markdown editors I use, MarkdownPad 2 and Notepad++ with NppMarkdownPanel, and previewers 1218 Seer and QuickLook display images regardless of back/forward slash; guess that's why I didn't spot this as the solution earlier.

Darthagnon commented 6 months ago

I just realised, 1218 Seer uses Pandoc v1.16.0.2 under the hood, and when previewing Markdown files with linked images on Windows, it does the opposite to the issue I'm observing here with Pandoc v3.1.13: images linked with backslashes \ are not displayed, but images linked with forward slashes / are displayed.

Although, on closer examination, I'm not sure if it's using Pandoc to render Markdown, as the plugin folder only contains scripts for DOCX and EPUB:

{
    "name": "docx2md",
    "suffix": ["docx","odt"], 
    "exec": "pandoc.exe -s \"*SEER_INPUT_PATH*\" -t markdown -o \"*SEER_OUTPUT_PATH*.md\""
}
{
    "name": "epub2text",
    "suffix": ["epub"],
    "exec": "pandoc.exe -s \"*SEER_INPUT_PATH*\" -t plain -o \"*SEER_OUTPUT_PATH*.txt\""
}