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

How to add images from root? #850

Closed
rilc0n opened this issue May 15, 2019 · 24 comments
Closed

How to add images from root? #850

rilc0n opened this issue May 15, 2019 · 24 comments
Labels
bug confirmed as a bug path-resolving

Comments

@rilc0n
Copy link

rilc0n commented May 15, 2019

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

@timaschew
Copy link
Member

@rilc0n
Copy link
Author

rilc0n commented May 16, 2019

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

@timaschew timaschew reopened this Jun 10, 2019
@timaschew
Copy link
Member

Hmm, it’s maybe a bug

@marcantoinem
Copy link

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

@tianyw0
Copy link

tianyw0 commented Aug 18, 2019

Hmm ..
this bug is fixed?

@marcantoinem
Copy link

marcantoinem commented Aug 18, 2019

Yes, now it works (with a workaround)

@tianyw0
Copy link

tianyw0 commented Aug 19, 2019

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.

@tianyw0
Copy link

tianyw0 commented Aug 19, 2019

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 ?

@marcantoinem
Copy link

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.

@marcantoinem
Copy link

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

@tianyw0
Copy link

tianyw0 commented Aug 19, 2019

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.

@ShusenTang
Copy link

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

@gigaga
Copy link

gigaga commented Nov 26, 2019

I've the same problem :(

@anikethsaha anikethsaha added the bug confirmed as a bug label Nov 26, 2019
@anikethsaha
Copy link
Member

It's quite difficult to cover all the cases with a single syntax. I will try to look around this soon.

@gigaga
Copy link

gigaga commented Nov 26, 2019

@anikethsaha the behavior should be in function of relativePath?
Currently even if this parameter is false, img path generated still is in relative.

@anikethsaha
Copy link
Member

@anikethsaha the behavior should be in function of relativePath?

Yes

Currently even if this parameter is false, img path generated still is in relative

Need an investigation about this.

@stale
Copy link

stale bot commented Feb 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Feb 4, 2020
@stale stale bot closed this as completed Feb 11, 2020
@cptcanuck
Copy link

This is still an issue.

@bajins
Copy link

bajins commented Mar 6, 2020

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}">`
        }
    }
}

@ngpeijiun
Copy link

ngpeijiun commented Jul 31, 2020

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);
});

ianychoi added a commit to ianychoi/Web-Dev-For-Beginners that referenced this issue Dec 25, 2020
ianychoi added a commit to ianychoi/Web-Dev-For-Beginners that referenced this issue Dec 25, 2020
ianychoi added a commit to ianychoi/Web-Dev-For-Beginners that referenced this issue Dec 25, 2020
Using "<img src />" HTML cannot guarantee relative paths.
The issue is being investigated but using a markdown table format
would be an alternative approach.

- FYI: docsifyjs/docsify#850
ianychoi added a commit to ianychoi/Web-Dev-For-Beginners that referenced this issue Dec 25, 2020
Using "<img src />" HTML cannot guarantee relative paths.
The issue is being investigated but using a markdown table format
would be an alternative approach.

- FYI: docsifyjs/docsify#850

(cherry picked from commit 36cacc5)
@computerphilosopher
Copy link

computerphilosopher commented Feb 16, 2021

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.

@Maxlinn
Copy link

Maxlinn commented Apr 16, 2022

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

ikfly added a commit to ikfly/docsify that referenced this issue Apr 22, 2022
…ve method as use same router with markdown file then remove beginning # (docsifyjs#877docsifyjs#850)
ikfly added a commit to ikfly/docsify that referenced this issue Apr 22, 2022
…, solve method as use same router with markdown file then remove beginning "#" (docsifyjs#877docsifyjs#850)
dev-captain pushed a commit to dev-captain/Web_project that referenced this issue Feb 22, 2023
Using "<img src />" HTML cannot guarantee relative paths.
The issue is being investigated but using a markdown table format
would be an alternative approach.

- FYI: docsifyjs/docsify#850
devshopier added a commit to devshopier/Web-project that referenced this issue May 15, 2023
Using "<img src />" HTML cannot guarantee relative paths.
The issue is being investigated but using a markdown table format
would be an alternative approach.

- FYI: docsifyjs/docsify#850
@ninjadev64
Copy link

same issue here!

fleissigguy pushed a commit to fleissigguy/Html that referenced this issue Feb 21, 2024
Using "<img src />" HTML cannot guarantee relative paths.
The issue is being investigated but using a markdown table format
would be an alternative approach.

- FYI: docsifyjs/docsify#850
@jhildenbiddle
Copy link
Member

Bug acknowledged. Tracking with #1891.

tesla0722 added a commit to tesla0722/Web-Dev-For-Beginners that referenced this issue Mar 2, 2024
Using "<img src />" HTML cannot guarantee relative paths.
The issue is being investigated but using a markdown table format
would be an alternative approach.

- FYI: docsifyjs/docsify#850
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug confirmed as a bug path-resolving
Projects
None yet
Development

No branches or pull requests