Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixing behaviour for when an link is root-relative #850 #877#1339

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
weijunyu wants to merge13 commits intodocsifyjs:develop
base:develop
Choose a base branch
Loading
fromweijunyu:root-relative-images

Conversation

@weijunyu
Copy link

Summary

This PR addresses#850 and most likely#877

When rendering image tags, render the image URL starting from thebase path if the image URL is root-relative, e.g./assets/my-image.png. Currently, root-relative paths are treated in the same way as normal relative paths which is not consistent with the behaviour of HTML img tags or markedjs compilation output.

Example

Given basePath = "" and the current file being/advanced/guide.md:

![](/assets/my-image.png) previously compiled to<img src="/advanced/assets/my-image.png></img>, where it is generally expected to render<img src="/assets/my-image.png></img>

This is in line with how HTMLimg tags work and how marked.js compiles its image tags.

More advanced example

Given basePath = "/docs/" and directory structure:

└── docs    ├── _sidebar.md    ├── assets        ├── my-image.png    └── subfolder        ├── _sidebar.md        ├── guide.md

In docs/subfolder/guide.md:

![](/assets/my-image.png) --> <img src="/docs/assets/my-image.png></img>

While previous behaviour would have been:

![](/assets/my-image.png) --> <img src="/docs/subfolder/assets/my-image.png></img>

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Repo settings
  • Other, please describe:

If changing the UI of default theme, please provide thebefore/after screenshot:

Does this PR introduce a breaking change? (check one)

  • Yes
  • [] No

If yes, please describe the impact and migration path for existing applications:

This can possibly break existing repos who are relying on normal relative path behaviour even when using root-relative paths in their markdown, and hence have images located within subfolders. I have looked through some repos however and could not find any instances of this, since this is generally not how image link URLs are expected to behave.

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g.fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome (84)
  • Firefox (78)
  • Safari (13.1.2)
  • Edge
  • IE

If adding anew feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

To avoid wasting your time, it's best to open afeature request issue first and wait for approval before working on it.

When rendering image tags, would render the image URL from base pathif the image URL is root-relative, ie starts with '/'.This is would make the behaviour of image URLs more predictable.
@vercel
Copy link

vercelbot commentedAug 17, 2020
edited
Loading

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect:https://vercel.com/docsify-core/docsify-preview/kr6q5t7my
✅ Preview:https://docsify-preview-git-fork-weijunyu-root-relative-images.docsify-core.vercel.app

@codesandbox-ci
Copy link

codesandbox-cibot commentedAug 17, 2020
edited
Loading

This pull request is automatically built and testable inCodeSandbox.

To see build info of the built libraries, clickhere or the icon next to each commit SHA.

Latest deployment of this branch, based on commiteee7754:

SandboxSource
docsify-templateConfiguration

Copy link
Member

@anikethsahaanikethsaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you add some test case here ?

also, it might be a breaking change ! may be doing this behind an option?

cc @docsifyjs/core thoughts?

@weijunyu
Copy link
Author

Agreed on doing this behind an option, will work on that and some tests. Thanks!

anikethsaha reacted with thumbs up emoji

If rootRelativeImageURL is false (default), current behaviour remains the same.If rootRelativeImageURL is true, images with root-relative URLs would berendered exactly as specified.E.g. ![](/assets/image.png) --> <img src="/assets/image.png" />If rootRelativeImageURL is a string, that would be treated as the pathto which root-relative image paths resolve.E.g.:config: { rootRelativeImageURL: "docs" }![](/assets/image.png) --> <img src="/docs/assets/image.png" />
Copy link
Member

@trusktrtrusktr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is good. Yeah, it's a breaking change, so until V5 it will need to be behind an option.

We are looking to add tests to all new changes. Seedocsify.test.js for an example of a test that loads a local Docsify site. Then you can write some code that checks that the image tag has the right src.

@weijunyu
Copy link
Author

Added new behaviour and tests.

Config for this follows the behaviour for some of the existing options likebasePath etc.

config.rootRelativeImageURL = false (default setting)

  • No change from previous behaviour.

config.rootRelativeImageURL = true

  • Root-relative image URLs are taken as-is, e.g.:![](/assets/image.png) --> <img src="/assets/image.png"/>

config.rootRelativeImageURL = [string]

  • Root-relative image URL would have the string prefixed, e.g.:![](/assets/image.png) --> <img src="/[string from config]/assets/image.png />

Co-authored-by: Anix <anik220798@gmail.com>
anikethsaha
anikethsaha previously approved these changesAug 23, 2020
@anikethsaha
Copy link
Member

Thanks

@weijunyu
Copy link
Author

Please don't merge yet, will update docs as well.

This broke the case where config.rootRelativeImageURL is set totrue --> empty string --> false, which is treated differently by the compiler.Added descriptin in configuration.md
Copy link
Member

@Koooooo-7Koooooo-7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

thx for ur input. 👍

@anikethsaha
Copy link
Member

cc@trusktr can you review this ? you have a request change pending I suppose.

@baicaihenxiao
Copy link

I hope this bug can be solved soon...

simonmaris reacted with thumbs up emoji

@Joaxin
Copy link

I hope this bug can be solved soon...

still not fixed

petrbroz and nicolas707 reacted with thumbs up emoji

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

Reviewers

@anikethsahaanikethsahaanikethsaha approved these changes

@Koooooo-7Koooooo-7Koooooo-7 approved these changes

@sy-recordssy-recordssy-records approved these changes

@trusktrtrusktrAwaiting requested review from trusktr

@jhildenbiddlejhildenbiddleAwaiting requested review from jhildenbiddle

Requested changes must be addressed to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@weijunyu@anikethsaha@baicaihenxiao@Joaxin@trusktr@Koooooo-7@sy-records

[8]ページ先頭

©2009-2025 Movatter.jp