Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Relative link in Markdown images should not expand to local path when converted to HTML #146

Open
nhahtdh opened this issue Oct 27, 2014 · 8 comments

Comments

@nhahtdh
Copy link

nhahtdh commented Oct 27, 2014

When we put an image in Markdown using a relative path:

![](relative/path.png)

In current version (mine is 0.136.0, but there are probably no change to this in newer versions), the relative path is expanded to local absolute path to the image when converted to HTML:

<img src="e:\folder\relative\path.png" alt>

Following the behavior when specifying a plain link, I think the relative path should not be expanded. In other words (as QuadPiece has commented):

<img src="relative\path.png" alt>

Extra work is needed to relativize the links when we want to use the HTML on a webpage.

@nhahtdh nhahtdh changed the title Relative link in Markdown images should not expand to local path in HTML Relative link in Markdown images should not expand to local path when converted to HTML Oct 27, 2014
@kevinsawicki
Copy link
Contributor

Just to confirm, what do you think relative/path.png should be resolved to specifically?

@QuadPiece
Copy link

I am guessing he expects it should simply end up as:

<img src="relative/path.png" alt>

As that is how people manually apply relative links.

If a person clicks this link while he is on example.com/folder, it will lead to example.com/folder/relative/path.png

@karas1999
Copy link

Is there any solution for this?
I was trying to export the html to my customers in a zip file with many relative linked images. e.g. ![img](img/aaa.png) .
It is OK in the markdown preview, but when I export the html file and send the zip to customers, all the image links are not working. As when I check out the html code, it all automatically add a absolute link like:
<img src="/Users/Karas/work/temp/img/aaa.png" alt="img">
This is totally useless as when I send the whole folder to others. Why not just remain the relative link in the HTML code?

@ruijun
Copy link

ruijun commented Jun 16, 2016

@karas1999 How did you deal with this problem?

@karas1999
Copy link

karas1999 commented Jun 17, 2016

@ruijun

I just quit Atom and went back to my old friend Sublime Text. It has much more plug-ins to improve markdown editing experience for me.

But I do had found a way to solve this problem in Atom:

  1. You need to install markdown-preview-plus first and make it enabled. Because you can't edit the code for markdown-preview as it is a built-in package, but you can edit the code of markdown-preview-plus.

  2. Open the package folder and open lib/renderer.coffee

  3. Comment out line 107 & 108:

    ```coffee
    # else
    #        src = path.resolve(path.dirname(filePath), src)
    ```
    
  4. Restart Atom to see if it works.

Sorry that I already deleted Atom so I'm not sure of this solution. If it's not working, you may need to do some more experiment to the code.

You can even try Base64 encode all the images when exported to html. Then you don't need to bind the image with html file any more.

@ruijun
Copy link

ruijun commented Jun 17, 2016

@karas1999 Thank you. I try it later.

@seijikun
Copy link

seijikun commented Nov 17, 2016

Not only does it not work when the folder is moved, but some browsers (at least Firefox) do not allow absolute paths on the local filesystem anymore. So even locally, when the path is perfectly fine - all pictures are missing.

@ShadowLNC
Copy link

Firefox allows absolute paths, but I've found I need to add file:/// to the beginning of the URI. Either way, it's not possible to view images in Firefox using the rendered HTML at the current time.

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

No branches or pull requests

8 participants