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

Have --self-contained use alt text when images are missing instead of failing #7904

Closed
lucalenardi opened this issue Feb 9, 2022 · 7 comments
Labels

Comments

@lucalenardi
Copy link

lucalenardi commented Feb 9, 2022

Explain the problem.

Not sure if this is actually a bug or an expected behaviour, so sorry if this is not the right place to report.

Starting from a simple test.md file, with a markdown command such as ![my image](./myimage.png)

If the image exists, everything is ok, but if the image does not exist, I have the following behaviours:

  1. with latex output: pandoc returns a warning message on the command line regarding the missing image and replaces the image with the alternative text "my image"
  2. with html output and --self-contained option: pandoc returns an missing file error: File ./myimage.png not found in resource path and exits without completing the process using the alternative text (which is the default for html).

The same also happens with raw html tags: <img> and <embded> trying to embed a pdf file in the html.

It seems to be related to the --self-contained option, as removing it actually populate the src attribute in the html tag ignoring the file existence.

It may be useful to have pandoc generates the final output with alternative texts – or maybe just completes the generation of the output file with warnings – in contexts where an automation runs a script that involves pandoc and not all assets are already available (es. some appendix as pdf, or some images).

Pandoc version?

pandoc 2.17.1.1 on Docker image pandoc/latex.

@lucalenardi lucalenardi added the bug label Feb 9, 2022
@jgm jgm changed the title Alternative text for embedded contents if missing (i.e. img and embed tags) Have --self-contained use alt text when images are missing instead of failing Feb 9, 2022
@jgm
Copy link
Owner

jgm commented Feb 9, 2022

I'm not sure what the best behavior is. Currently we try to guarantee that a file produced with --self-contained really is self-contained. If we left the missing src in there, it wouldn't be. But I can see the point of the request. Would be interested in feedback from others.

@mb21
Copy link
Collaborator

mb21 commented Feb 10, 2022

Emitting a warning instead of failing hard seems like a sensible behaviour, considering that's what pdflatex and browsers do as well.

we try to guarantee that a file produced with --self-contained really is self-contained

if the image has been deleted (or was at a URL that's a 404 now), then the file cannot be any more self-contained than that, so I'd argue that principle isn't violated.

Only thing I can think of that could break with this change is CI scripts that rely on pandoc's non-zero exit code in this case, but that's a very edge case...

@cagix
Copy link
Contributor

cagix commented Feb 10, 2022

i kind of like the behaviour when using latex as backend: emit a clear warning and produce some valid output using the alt text.

@jgm
Copy link
Owner

jgm commented Feb 11, 2022

In the PDF module we use fillMediaBag, which catches errors in fetchItem and produces a warning.
We could add similar error handling to SelfContained.

@jgm jgm closed this as completed in 6199668 Feb 11, 2022
damon-sava-stanley pushed a commit to damon-sava-stanley/pandoc that referenced this issue Feb 11, 2022
with an error, if a resource can't be found.
Closes jgm#7904.

Make improvements for jgm#7908

Don't reinvent the wheel of `isPrefixOf` and pull out some spooky
`head`s.
@gabyx
Copy link

gabyx commented Apr 5, 2022

@jgm An option --warnings-as-errors would have been nice. Because, as in other languages its common to have all warnings treated as errors, at least if the users wants.

@tarleb
Copy link
Collaborator

tarleb commented Apr 5, 2022

@gabyx --fail-if-warnings?

@gabyx
Copy link

gabyx commented Apr 5, 2022

Sorry my bad, true that exists and I am already using. Sorry.

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

No branches or pull requests

6 participants