diff --git a/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap b/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap index 29aa2ee8cb..19cc4ef9f2 100644 --- a/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap +++ b/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap @@ -5,6 +5,10 @@ exports[`snippet import snippet 1`] = ` // .. } +
# Sample snippet file with no filename extension.
+FROM ubuntu:latest
+CMD echo hello!
+
`; exports[`snippet import snippet with highlight multiple lines 1`] = ` diff --git a/packages/@vuepress/markdown/__tests__/fragments/Dockerfile b/packages/@vuepress/markdown/__tests__/fragments/Dockerfile new file mode 100644 index 0000000000..6cd64bef1d --- /dev/null +++ b/packages/@vuepress/markdown/__tests__/fragments/Dockerfile @@ -0,0 +1,3 @@ +# Sample snippet file with no filename extension. +FROM ubuntu:latest +CMD echo hello! diff --git a/packages/@vuepress/markdown/__tests__/fragments/code-snippet.md b/packages/@vuepress/markdown/__tests__/fragments/code-snippet.md index f6fbf4048b..a0f536ec06 100644 --- a/packages/@vuepress/markdown/__tests__/fragments/code-snippet.md +++ b/packages/@vuepress/markdown/__tests__/fragments/code-snippet.md @@ -1 +1,3 @@ <<< @/packages/@vuepress/markdown/__tests__/fragments/snippet.js + +<<< @/packages/@vuepress/markdown/__tests__/fragments/Dockerfile diff --git a/packages/@vuepress/markdown/lib/snippet.js b/packages/@vuepress/markdown/lib/snippet.js index cc0366242f..7902bf3e48 100644 --- a/packages/@vuepress/markdown/lib/snippet.js +++ b/packages/@vuepress/markdown/lib/snippet.js @@ -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)