Skip to content

How to add images from root? #850

Description

@rilc0n

For example, I have 2 folders in the root directory. There is a picture in the first folder (images).

The second folder (docs) contains the markdown file.

How do I insert an image into this markdown file that is located in the folder (images).

If I put it this way:

![](/images/testimage.jpg)

He tries to add it like this:

/docs/images/testimage.jpg

Activity

  1. timaschew commented on May 16, 2019

    @timaschew
    Member
  2. rilc0n commented on May 16, 2019

    @rilc0n
    Author

    This changes the links but not the path to pictures. Am I doing something wrong?

  3. timaschew commented on Jun 10, 2019

    @timaschew
    Member

    Hmm, it’s maybe a bug

  4. marcantoinem commented on Aug 8, 2019

    @marcantoinem

    I confirm this is a bug. When you use
    ![](/img/img.png)
    it doesn't work, but when you use
    <img src='/img/img.png'></img>
    it works

  5. tianyw0 commented on Aug 18, 2019

    @tianyw0

    Hmm ..
    this bug is fixed?

  6. marcantoinem commented on Aug 18, 2019

    @marcantoinem

    Yes, now it works (with a workaround)

  7. tianyw0 commented on Aug 19, 2019

    @tianyw0

    Hey @LemarkNova , Thanks for reply.

    I am confused about the img tag compile result.

    my markdown content is :

    ![my img](/myimg.png)

    The docsify compiled result is :

    <img src="/foldername/subfoldername/myimg.png" alt.../>

    my expected result is :

    <img src="/myimg.png" alt.../>

    because my all static img file is just in a single folder.

  8. tianyw0 commented on Aug 19, 2019

    @tianyw0

    I found that this 「long path」is not caused by "marked" —— docsify compile markdown file by it,

    It seems caused docsify ?

    Something could be config ?

  9. marcantoinem commented on Aug 19, 2019

    @marcantoinem

    No finally it isn't fixed, I remember that I just use a workaround to use image in markdown:
    I use ../picturefolder/picture.jpg. So the real problem is that docsify doesn't compile correctly the markdown image. I don't know how you compile the markdown, but the problem is in the compilation of the markdown like in your previous comment.

  10. marcantoinem commented on Aug 19, 2019

    @marcantoinem

    Does Docsify use the latest version of marked? But I just try with marked and it work.

  11. tianyw0 commented on Aug 19, 2019

    @tianyw0

    Thanks for your help. I note the workaround way.

    I do nothing about the compilation of markdown files, just do some steps from the official documentation.

    I am not sure the version of marked, but the docsify I installed is the latest version.

  12. ShusenTang commented on Oct 21, 2019

    @ShusenTang

    No finally it isn't fixed, I remember that I just use a workaround to use image in markdown:
    I use ../picturefolder/picture.jpg. So the real problem is that docsify doesn't compile correctly the markdown image. I don't know how you compile the markdown, but the problem is in the compilation of the markdown like in your previous comment.

    Hi, could you please help me? #936

  13. 11 remaining items

  14. bajins commented on Mar 6, 2020

    @bajins
    hook.beforeEach(function(content) {
        return content.replace(new RegExp("/images", 'ig'), "../images");
    })

    or

    hook.afterEach(function(html, next) {
        let reg = new RegExp(vm.config.basePath + ".*/images", 'ig');
        html = html.replace(reg, vm.config.basePath + "images");
        next(html);
    })

    or

    markdown: {
        // https://marked.js.org/#/USING_PRO.md#renderer
        renderer: {
            image: function(href, title) {
                return `<img src="${href}" data-origin="${href}" alt="${title}">`
            }
        }
    }
  15. ngpeijiun commented on Jul 31, 2020

    @ngpeijiun

    In core/render/compiler/image.js

        import { isAbsolutePath, isRelativePath, getPath, getParentPath } from '../../router/util';
    
        ...
    
        if (!isAbsolutePath(href)) {
          url = isRelativePath(href) ?
            getPath(contentBase, getParentPath(router.getCurrentPath()), href) :
            getPath(contentBase, href);
        }
    

    In core\router\util.js

    export const isRelativePath = cached(path => {
      return /^[^\/]/g.test(path);
    });
    
  16. computerphilosopher commented on Feb 16, 2021

    @computerphilosopher

    If your image is in GitHub repo, Use 'img src' instead of markdown and attach "?raw=true" to end of image's URL.

    <img src="https://github.com/your/repo/blob/master/docs/images/img.png?raw=true"</img>
    

    I don't know why, but it works.

  17. Maxlinn commented on Apr 16, 2022

    @Maxlinn

    I come up with the same problem, i think the most convinent way is to turn ![]() syntax into <img src="" alt="">.

  18. nekename commented on Sep 9, 2023

    @nekename

    same issue here!

  19. jhildenbiddle commented on Mar 2, 2024

    @jhildenbiddle
    Member

    Bug acknowledged. Tracking with #1891.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions