fix($markdown): code snippets should not split path on space (close: #1505)(#1509)

This commit is contained in:
Nick Evans
2019-04-03 23:34:17 +08:00
committed by ULIVZ
parent 3cc805d9a2
commit 7b4c4b0d3d
5 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -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, '')
@@ -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 () {
// ..
@@ -0,0 +1 @@
<<< @/test/markdown/fragments/snippet with spaces.js {1}
@@ -0,0 +1,3 @@
export default function () {
// ..
}
+6
View File
@@ -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()
})
})