Skip to content

Commit 8aa032f

Browse files
committedAug 28, 2023
fix: resolve snippets from original file path - align with include behavior
1 parent 4f01f1a commit 8aa032f

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed
 

‎src/node/markdown/plugins/snippet.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ export const snippetPlugin = (md: MarkdownIt, srcDir: string) => {
125125
title ? `[${title}]` : ''
126126
}`
127127

128-
const resolvedPath = path.resolve(
129-
path.dirname((state.env as MarkdownEnv).path),
130-
filepath
131-
)
128+
const { realPath, path: _path } = state.env as MarkdownEnv
129+
const resolvedPath = path.resolve(path.dirname(realPath ?? _path), filepath)
130+
132131
// @ts-ignore
133132
token.src = [resolvedPath, region.slice(1)]
134133
token.markup = '```'

‎src/node/markdownToVue.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ export async function createMarkdownToVueRenderFn(
128128
path: file,
129129
relativePath,
130130
cleanUrls,
131-
includes
131+
includes,
132+
realPath: fileOrig
132133
}
133134
const html = md.render(src, env)
134135
const {

‎types/shared.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,5 @@ export interface MarkdownEnv {
136136
cleanUrls: boolean
137137
links?: string[]
138138
includes?: string[]
139+
realPath?: string
139140
}

0 commit comments

Comments
 (0)
Please sign in to comment.