Skip to content

Commit

Permalink
fix($markdown): support path without file extension when importing co…
Browse files Browse the repository at this point in the history
…de snippets (#2677)
  • Loading branch information
mitjat authored Feb 18, 2021
1 parent 3ab9fca commit bb4ae4e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ exports[`snippet import snippet 1`] = `
// ..
}
</code></pre>
<pre><code># Sample snippet file with no filename extension.
FROM ubuntu:latest
CMD echo hello!
</code></pre>
`;

exports[`snippet import snippet with highlight multiple lines 1`] = `
Expand Down
3 changes: 3 additions & 0 deletions packages/@vuepress/markdown/__tests__/fragments/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Sample snippet file with no filename extension.
FROM ubuntu:latest
CMD echo hello!
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<<< @/packages/@vuepress/markdown/__tests__/fragments/snippet.js

<<< @/packages/@vuepress/markdown/__tests__/fragments/Dockerfile
2 changes: 1 addition & 1 deletion packages/@vuepress/markdown/lib/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ module.exports = function snippet (md, options = {}) {
*
* captures: ['/path/to/file.extension', 'extension', '#region', '{meta}']
*/
const rawPathRegexp = /^(.+(?:\.([a-z]+)))(?:(#[\w-]+))?(?: ?({\d+(?:[,-]\d+)*}))?$/
const rawPathRegexp = /^(.+?(?:\.([a-z]+))?)(?:(#[\w-]+))?(?: ?({\d+(?:[,-]\d+)*}))?$/

const rawPath = state.src.slice(start, end).trim().replace(/^@/, root).trim()
const [filename = '', extension = '', region = '', meta = ''] = (rawPathRegexp.exec(rawPath) || []).slice(1)
Expand Down

0 comments on commit bb4ae4e

Please sign in to comment.