Skip to content

feat: new option: restrict path aliases that do not start with the prefix (close #1646)#1647

Open
LincZero wants to merge 16 commits intovuepress:mainfrom
LincZero:main
Open

feat: new option: restrict path aliases that do not start with the prefix (close #1646)#1647
LincZero wants to merge 16 commits intovuepress:mainfrom
LincZero:main

Conversation

@LincZero
Copy link
Copy Markdown

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Provide a description in this PR that addresses what the PR is solving. If this PR is going to solve an existing issue, please reference the issue (e.g. close #123).

What is the purpose of this pull request?

  • Bug fix
  • New feature
  • Documentation update
  • Other

Description

close #1646

Screenshots

Before

After

Copy link
Copy Markdown
Member

@Mister-Hope Mister-Hope left a comment

Choose a reason for hiding this comment

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

Since Vite's default static file is covering media files, we can also handle video and audio here as well.

Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts Outdated
Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts Outdated
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 29, 2025

Pull Request Test Coverage Report for Build 21834429282

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 74.155%

Totals Coverage Status
Change from base Build 21831331239: 0.1%
Covered Lines: 700
Relevant Lines: 945

💛 - Coveralls

@LincZero LincZero requested a review from Mister-Hope April 29, 2025 18:47
@LincZero LincZero changed the title feat: restrictRelativePath option feat: restrictRelativePath option (close #1646) Apr 29, 2025
Copy link
Copy Markdown
Member

@Mister-Hope Mister-Hope left a comment

Choose a reason for hiding this comment

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

Like I said previously, video and audio tags shall also be tracked.

This means you should also modify the regexp in the first replacer function.

Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts Outdated
Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts Outdated
Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts Outdated
Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts Outdated
@LincZero
Copy link
Copy Markdown
Author

LincZero commented Apr 29, 2025

Should the unit test of the media tag be conducted in assetsPlugin.spec.ts.

This won't be available for supplementation until tomorrow.

@LincZero LincZero requested a review from Mister-Hope April 29, 2025 21:24
@Mister-Hope
Copy link
Copy Markdown
Member

Mister-Hope commented Apr 30, 2025

Audio and video tags can have src attribute.

Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts Outdated
@LincZero LincZero requested a review from Mister-Hope April 30, 2025 09:46
Mister-Hope
Mister-Hope previously approved these changes Apr 30, 2025
@Mister-Hope Mister-Hope requested a review from meteorlxy April 30, 2025 09:50
@Mister-Hope
Copy link
Copy Markdown
Member

@meteorlxy Needs review here.

@Mister-Hope
Copy link
Copy Markdown
Member

Updated: we have finished our work on #1606, and we might still need this in some cases.

We will try to merge this soon after merging #1606

@Mister-Hope
Copy link
Copy Markdown
Member

Can you try to rework this under the new bundler resolution?

The logic would be more simple than before.

@LincZero LincZero marked this pull request as draft March 20, 2026 08:04
@LincZero LincZero changed the title feat: restrictRelativePath option (close #1646) feat: new option: restrict path aliases that do not start with the prefix (close #1646) Mar 20, 2026
Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts Outdated
@LincZero LincZero requested a review from Mister-Hope March 20, 2026 10:06
Mister-Hope
Mister-Hope previously approved these changes Mar 20, 2026
@Mister-Hope Mister-Hope marked this pull request as ready for review March 20, 2026 10:29
Copilot AI review requested due to automatic review settings March 20, 2026 10:29
@Mister-Hope
Copy link
Copy Markdown
Member

You should update e2e test at markdown/image

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new aliasSupport option to the markdown assetsPlugin to control how “non-strict” asset paths (those not starting with ./, ../, /, or a protocol) are treated—either as aliases (current behavior) or as relative paths (by prepending ./). It also expands the HTML asset rewriting to include additional media tags beyond <img>.

Changes:

  • Add aliasSupport?: boolean | '@-prefix' to assetsPlugin and thread it into link resolution logic.
  • Extend HTML asset attribute rewriting from <img> to <audio>, <video>, and <source>.
  • Add test coverage for HTML media tags using the new option.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts Adds aliasSupport option + expands HTML tag matching to more media tags.
packages/markdown/src/plugins/assetsPlugin/resolveLink.ts Implements the aliasSupport behavior in link resolution.
packages/markdown/tests/plugins/assetsPlugin.spec.ts Adds tests for media tags and the new option behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/markdown/src/plugins/assetsPlugin/resolveLink.ts
Comment thread packages/markdown/tests/plugins/assetsPlugin.spec.ts Outdated
Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts
Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts
Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts
Comment thread packages/markdown/src/plugins/assetsPlugin/resolveLink.ts Outdated
Comment thread packages/markdown/src/plugins/assetsPlugin/resolveLink.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/markdown/src/plugins/assetsPlugin/resolveLink.ts Outdated
Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts
Comment thread packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts
Comment thread e2e/docs/markdown/images/images.md Outdated
Comment thread packages/markdown/tests/plugins/assetsPlugin.spec.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Add img_alias_limit

4 participants