Skip to content

Commit 7b4c4b0

Browse files
nie7321ulivz
authored andcommitted
fix($markdown): code snippets should not split path on space (close: #1505)(#1509)
1 parent 3cc805d commit 7b4c4b0

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

lib/markdown/snippet.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function snippet (md, options = {}) {
2424
const start = pos + 3
2525
const end = state.skipSpacesBack(max, pos)
2626
const rawPath = state.src.slice(start, end).trim().replace(/^@/, root)
27-
const filename = rawPath.split(/[{\s]/).shift()
27+
const filename = rawPath.split(/{/).shift().trim()
2828
const content = fs.existsSync(filename) ? fs.readFileSync(filename).toString() : 'Not found: ' + filename
2929
const meta = rawPath.replace(filename, '')
3030

test/markdown/__snapshots__/snippet.spec.js.snap

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
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+
<br>
7+
<br>
8+
<br>
9+
</div>export default function () { // .. }
10+
`;
11+
312
exports[`snippet import snippet 1`] = `
413
<pre><code class="language-js">export default function () {
514
// ..
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<<< @/test/markdown/fragments/snippet with spaces.js {1}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function () {
2+
// ..
3+
}

test/markdown/snippet.spec.js

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

0 commit comments

Comments
 (0)