Skip to content

Commit

Permalink
fix($markdown): Snippets should allow spaces in file path (closes #1505
Browse files Browse the repository at this point in the history
…) (#1517)
  • Loading branch information
nie7321 authored and ulivz committed Apr 6, 2019
1 parent dabf506 commit 5c307c9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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`] = `
<div class="highlight-lines">
<div class="highlighted">&nbsp;</div>
<div class="highlighted">&nbsp;</div>
<div class="highlighted">&nbsp;</div><br>
</div>export default function () {
// ..
}
`;
exports[`snippet import snippet 1`] = `
<pre><code class="language-js">export default function () {
// ..
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<<< @/packages/@vuepress/markdown/__tests__/fragments/snippet with spaces.js {1-3}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function () {
// ..
}
6 changes: 6 additions & 0 deletions packages/@vuepress/markdown/__tests__/snippet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
2 changes: 1 addition & 1 deletion packages/@vuepress/markdown/lib/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c307c9

Please sign in to comment.