max-heller / mdbook-pandoc

A mdbook backend powered by Pandoc.
Apache License 2.0
97 stars 7 forks source link

Replace unresolvable remote images with their descriptions #96

Closed max-heller closed 2 months ago

max-heller commented 3 months ago

Mirror Pandoc's behavior of replacing remote images that can't be loaded with their description. We only resolve images that Pandoc can't handle, so if we fail to resolve it, we want to make sure the URL doesn't get to Pandoc, which would try and fail to process it.

This should be implemented here: https://github.com/max-heller/mdbook-pandoc/blob/aa239faad895dbdf2933aef79f936282a91dfe63/src/preprocess.rs#L226-L240

Sample Pandoc log for inspiration:

[WARNING] Could not fetch resource https://img.shields.io/github/actions/workflow/status/google/comprehensive-rust/build.yml?style=flat-square: HttpExceptionRequest Request {
    host                 = "img.shields.io"
    port                 = 443
    secure               = True
    requestHeaders       = []
    path                 = "/github/actions/workflow/status/google/comprehensive-rust/build.yml"
    queryString          = "?style=flat-square"
    method               = "GET"
    proxy                = Nothing
    rawBody              = False
    redirectCount        = 10
    responseTimeout      = ResponseTimeoutDefault
    requestVersion       = HTTP/1.1
    proxySecureMode      = ProxySecureWithConnect
  }
   (ConnectionFailure user error (Network.Socket.gai_strerror not supported: 11004))
Replacing image with description.

Identified in https://github.com/google/comprehensive-rust/issues/1911#issuecomment-2167612377