Skip to content

Commit 5c307c9

Browse files
nie7321ulivz
authored andcommitted
fix($markdown): Snippets should allow spaces in file path (closes #1505) (#1517)
1 parent dabf506 commit 5c307c9

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`snippet import snipets when the file has a space in the file path 1`] = `
4+
<div class="highlight-lines">
5+
<div class="highlighted">&nbsp;</div>
6+
<div class="highlighted">&nbsp;</div>
7+
<div class="highlighted">&nbsp;</div><br>
8+
</div>export default function () {
9+
// ..
10+
}
11+
`;
12+
313
exports[`snippet import snippet 1`] = `
414
<pre><code class="language-js">export default function () {
515
// ..
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<<< @/packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js {1-3}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function () {
2+
// ..
3+
}

packages/@vuepress/markdown/__tests__/snippet.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ describe('snippet', () => {
2424
const output = mdH.render(input)
2525
expect(output).toMatchSnapshot()
2626
})
27+
28+
test('import snipets when the file has a space in the file path', () => {
29+
const input = getFragment(__dirname, 'code-snippet-with-space-in-path.md')
30+
const output = mdH.render(input)
31+
expect(output).toMatchSnapshot()
32+
})
2733
})

packages/@vuepress/markdown/lib/snippet.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = function snippet (md, options = {}) {
4444
const start = pos + 3
4545
const end = state.skipSpacesBack(max, pos)
4646
const rawPath = state.src.slice(start, end).trim().replace(/^@/, root)
47-
const filename = rawPath.split(/[{\s]/).shift()
47+
const filename = rawPath.split(/{/).shift().trim()
4848
const meta = rawPath.replace(filename, '')
4949

5050
state.line = startLine + 1

0 commit comments

Comments
 (0)