Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: restrictRelativePath option 2
  • Loading branch information
LincZero committed Apr 29, 2025
commit 2b5e08d6180041f850d4828835c33272395a66e8
14 changes: 7 additions & 7 deletions packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export interface AssetsPluginOptions {
/**
* The strictness of the determination of relative paths
*
* - strict: startWith `./` or `../` -> relative path
* - half: no startWith `/` or `@` or `<protocol>` (`https?:` `data:`) -> relative path
* At this point, only aliases beginning with `@` are allowed to replace
* relative paths not beginning with `.`
* - no: no startWith `/` or `<protocol>` -> relative path
* When different options are set, the criteria for identifying relative paths are as follows:
*
* - true: start with `./` or `../`
* - false: no start with `/` or `<protocol header>`
* - '@-perfix': no start with `/` or `@` or `<protocol header>`
*/
restrictRelativePath?: 'half' | 'no' | 'strict'
restrictRelativePath?: boolean | '@-perfix'
}

/**
Expand All @@ -34,7 +34,7 @@ export const assetsPlugin: PluginWithOptions<AssetsPluginOptions> = (
{
absolutePathPrependBase = false,
relativePathPrefix = '@source',
restrictRelativePath = 'strict',
restrictRelativePath = true,
}: AssetsPluginOptions = {},
) => {
// wrap raw image renderer rule
Expand Down
8 changes: 4 additions & 4 deletions packages/markdown/src/plugins/assetsPlugin/resolveLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface ResolveLinkOptions {
env: MarkdownEnv
absolutePathPrependBase?: boolean
relativePathPrefix: string
strict?: 'half' | 'no' | 'strict'
strict?: boolean | '@-perfix'
}

export const resolveLink = (
Expand All @@ -15,7 +15,7 @@ export const resolveLink = (
env,
absolutePathPrependBase = false,
relativePathPrefix,
strict = 'no',
strict = false,
}: ResolveLinkOptions,
): string => {
// do not resolve data uri
Expand All @@ -26,9 +26,9 @@ export const resolveLink = (

// check if the link is relative path
const isRelativePath =
strict === 'strict'
strict === true
? /^\.{1,2}\//.test(link)
: strict === 'no'
: strict === false
? !link.startsWith('/') && !/[A-z]+:\/\//.test(link)
: !link.startsWith('/') &&
!link.startsWith('@') &&
Expand Down
Loading