diff --git a/lib/markdown/snippet.js b/lib/markdown/snippet.js index b21c0df93a..b8d93fc753 100644 --- a/lib/markdown/snippet.js +++ b/lib/markdown/snippet.js @@ -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, '') diff --git a/test/markdown/__snapshots__/snippet.spec.js.snap b/test/markdown/__snapshots__/snippet.spec.js.snap index 3c97bcddcc..f2f3ae5d89 100644 --- a/test/markdown/__snapshots__/snippet.spec.js.snap +++ b/test/markdown/__snapshots__/snippet.spec.js.snap @@ -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`] = ` +
export default function () {
// ..
diff --git a/test/markdown/fragments/code-snippet-with-space-in-path.md b/test/markdown/fragments/code-snippet-with-space-in-path.md
new file mode 100644
index 0000000000..57351aadbf
--- /dev/null
+++ b/test/markdown/fragments/code-snippet-with-space-in-path.md
@@ -0,0 +1 @@
+<<< @/test/markdown/fragments/snippet with spaces.js {1}
diff --git a/test/markdown/fragments/snippet with spaces.js b/test/markdown/fragments/snippet with spaces.js
new file mode 100644
index 0000000000..575039d1ec
--- /dev/null
+++ b/test/markdown/fragments/snippet with spaces.js
@@ -0,0 +1,3 @@
+export default function () {
+ // ..
+}
diff --git a/test/markdown/snippet.spec.js b/test/markdown/snippet.spec.js
index 0131132916..e99ed956ad 100644
--- a/test/markdown/snippet.spec.js
+++ b/test/markdown/snippet.spec.js
@@ -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()
+ })
})