question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

remark-download-images: use default black image when 404

See original GitHub issue

When we transform our markdown into latex, and some images lead to 404 error, remark-download-images generate a png file but with html content.

Here is an example from @motet-a tutorial:

![sprite](https://zestedesavoir.com/static/images/sprite.f651d381c5ba.png)

this image is not available. When generating latex, we get this error :

[
    {
        "column": 1,
        "name": "2142:1-2142:97",
        "line": 2142,
        "reason": "Received HTTP404 for: https://zestedesavoir.com/static/images/sprite.f651d381c5ba.png",
        "ruleId": "//zestedesavoir.com/static/images/sprite.f651d381c5ba.png",
        "fatal": false,
        "stack": "Error: Received HTTP404 for: https://zestedesavoir.com/static/images/sprite.f651d381c5ba.png\n    at Request.request.get.on (/opt/zmd/node_modules/remark-images-download/src/index.js:140:26)\n    at emitOne (events.js:121:20)\n    at Request.emit (events.js:211:7)\n    at Request.onRequestResponse (/opt/zmd/node_modules/request/request.js:1066:10)\n    at emitOne (events.js:116:13)\n    at ClientRequest.emit (events.js:211:7)\n    at HTTPParser.parserOnIncomingClient (_http_client.js:551:21)\n    at HTTPParser.parserOnHeadersComplete (_http_common.js:115:23)\n    at TLSSocket.socketOnData (_http_client.js:440:20)\n    at emitOne (events.js:116:13)\n    at TLSSocket.emit (events.js:211:7)\n    at addChunk (_stream_readable.js:263:12)\n    at readableAddChunk (_stream_readable.js:250:11)\n    at TLSSocket.Readable.push (_stream_readable.js:208:10)\n    at TLSWrap.onread (net.js:607:20)",
        "location": {
            "start": {
                "column": 1,
                "offset": 102942,
                "line": 2142
            },
            "indent": [],
            "end": {
                "column": 97,
                "offset": 103038,
                "line": 2142
            }
        },
        "message": "Received HTTP404 for: https://zestedesavoir.com/static/images/sprite.f651d381c5ba.png",
        "source": "https"
    }
]

When image is not properly formatted, latex fails (see https://github.com/zestedesavoir/latex-template/issues/98 ) so I wanted to read the error to generate a fake “black” image to ensure the pdf to be generated.

But as you can see, I have no clue of the generated file name. In this case it was images/D4AuEmg-ie/vr4WW3-8kIv.png .

The content is :

<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

expected

I think many possibilities are acceptable here :

  • in the error object, send the path to bad image file so that I can change it
  • automatically create a black square image when status is not 200 OK
  • change the image to “default.png” (configurable) when answer is not 200OK

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
motet-acommented, Dec 9, 2018

@vhf Yes, I have a bunch of improvements and fixes for remark-images-download on my box I have to share. I think I will submit a PR soon.

0reactions
vhfcommented, Aug 29, 2019

This has been released as:

  • remark-images-download@2.9.0
  • zmarkdown@6.1.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

Apache show a default image when there is a 404 error under ...
The first RewriteCond will check whether the incoming request is for a jpg file under /assets/user-images/ or not and the second RewriteCond ...
Read more >
Set default image when file not found (404) - Drupal Answers
Install and configure ImageCache Defaults module. ImageCache Defaults detects file paths in broken images (404 errors) generated by ImageCache (D6) and ...
Read more >
What Is a 404 Error? How to Deal With the Web Error
A 404 error indicates that the webpage you're trying to reach can't be found, and usually means that the page has moved or...
Read more >
Creating a custom Joomla 404 error page
First, create an article and call it “404 – Error: 404” or something to that effect. I chose that title because that's what...
Read more >
How to Make a Custom 404 Page | iloveseo.com
Keep visitors on the site with the help of a creative, custom 404 page. ... Usually comprising black text on a plain white...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found