Skip to content

Fix #1505 - Snippets should not split path on space #1509

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

Merged
merged 4 commits into from
Apr 3, 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
2 changes: 1 addition & 1 deletion lib/markdown/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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 content = fs.existsSync(filename) ? fs.readFileSync(filename).toString() : 'Not found: ' + filename
const meta = rawPath.replace(filename, '')

Expand Down
9 changes: 9 additions & 0 deletions test/markdown/__snapshots__/snippet.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// 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>
<br>
<br>
<br>
</div>export default function () { // .. }
`;

exports[`snippet import snippet 1`] = `
<pre><code class="language-js">export default function () {
// ..
Expand Down
1 change: 1 addition & 0 deletions test/markdown/fragments/code-snippet-with-space-in-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<<< @/test/markdown/fragments/snippet with spaces.js {1}
3 changes: 3 additions & 0 deletions test/markdown/fragments/snippet with spaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function () {
// ..
}
6 changes: 6 additions & 0 deletions test/markdown/snippet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ describe('snippet', () => {
const output = mdH.render(input)
expect(output).toMatchSnapshot()
})

test('import snipets when the file has a space in the file path', async () => {
const input = await getFragment('code-snippet-with-space-in-path')
const output = mdH.render(input)
expect(output).toMatchSnapshot()
})
})