Skip to content

Commit bb4ae4e

Browse files
authored
fix($markdown): support path without file extension when importing code snippets (#2677)
1 parent 3ab9fca commit bb4ae4e

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

‎packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ exports[`snippet import snippet 1`] = `
55
// ..
66
}
77
</code></pre>
8+
<pre><code># Sample snippet file with no filename extension.
9+
FROM ubuntu:latest
10+
CMD echo hello!
11+
</code></pre>
812
`;
913

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

‎packages/@vuepress/markdown/lib/snippet.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ module.exports = function snippet (md, options ={}){
137137
*
138138
* captures: ['/path/to/file.extension', 'extension', '#region', '{meta}']
139139
*/
140-
constrawPathRegexp=/^(.+(?:\.([a-z]+)))(?:(#[\w-]+))?(?:?({\d+(?:[,-]\d+)*}))?$/
140+
constrawPathRegexp=/^(.+?(?:\.([a-z]+))?)(?:(#[\w-]+))?(?:?({\d+(?:[,-]\d+)*}))?$/
141141

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

0 commit comments

Comments
(0)