diff --git a/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap b/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap index 1514907d3b..d62e87224e 100644 --- a/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap +++ b/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap @@ -1,5 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`snippet import snipets when the file has a space in the file path 1`] = ` +
export default function () {
// ..
diff --git a/packages/@vuepress/markdown/__tests__/fragments/code-snippet-with-space-in-path.md b/packages/@vuepress/markdown/__tests__/fragments/code-snippet-with-space-in-path.md
new file mode 100644
index 0000000000..659cb2586d
--- /dev/null
+++ b/packages/@vuepress/markdown/__tests__/fragments/code-snippet-with-space-in-path.md
@@ -0,0 +1 @@
+<<< @/packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js {1-3}
diff --git a/packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js b/packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js
new file mode 100644
index 0000000000..575039d1ec
--- /dev/null
+++ b/packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js
@@ -0,0 +1,3 @@
+export default function () {
+ // ..
+}
diff --git a/packages/@vuepress/markdown/__tests__/snippet.spec.js b/packages/@vuepress/markdown/__tests__/snippet.spec.js
index bd3a23cfae..4a2c65f8fe 100644
--- a/packages/@vuepress/markdown/__tests__/snippet.spec.js
+++ b/packages/@vuepress/markdown/__tests__/snippet.spec.js
@@ -24,4 +24,10 @@ describe('snippet', () => {
const output = mdH.render(input)
expect(output).toMatchSnapshot()
})
+
+ test('import snipets when the file has a space in the file path', () => {
+ const input = getFragment(__dirname, 'code-snippet-with-space-in-path.md')
+ const output = mdH.render(input)
+ expect(output).toMatchSnapshot()
+ })
})
diff --git a/packages/@vuepress/markdown/lib/snippet.js b/packages/@vuepress/markdown/lib/snippet.js
index b0b88f18f2..7713da90cb 100644
--- a/packages/@vuepress/markdown/lib/snippet.js
+++ b/packages/@vuepress/markdown/lib/snippet.js
@@ -44,7 +44,7 @@ module.exports = function snippet (md, options = {}) {
const start = pos + 3
const end = state.skipSpacesBack(max, pos)
const rawPath = state.src.slice(start, end).trim().replace(/^@/, root)
- const filename = rawPath.split(/[{\s]/).shift()
+ const filename = rawPath.split(/{/).shift().trim()
const meta = rawPath.replace(filename, '')
state.line = startLine + 1