Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix($markdown): Snippets should allow spaces in file path (closes #1505) #1517

Merged
merged 2 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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