From e629cd5ca33f3c6ea1733f80b78a9090a635ee52 Mon Sep 17 00:00:00 2001 From: Mitja T Date: Fri, 23 Oct 2020 15:29:12 +0200 Subject: [PATCH 1/2] fix($markdown): accept snippet paths with no extension --- .../markdown/__tests__/__snapshots__/snippet.spec.js.snap | 6 +++--- packages/@vuepress/markdown/__tests__/fragments/Dockerfile | 3 +++ .../@vuepress/markdown/__tests__/fragments/code-snippet.md | 2 +- packages/@vuepress/markdown/lib/snippet.js | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 packages/@vuepress/markdown/__tests__/fragments/Dockerfile diff --git a/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap b/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap index 29aa2ee8cb..6c7453b2f0 100644 --- a/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap +++ b/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`snippet import snippet 1`] = ` -
export default function () {
-  // ..
-}
+
# Sample snippet file with no filename extension.
+FROM ubuntu:latest
+CMD echo hello!
 
`; 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..0a434f0d74 100644 --- a/packages/@vuepress/markdown/__tests__/fragments/code-snippet.md +++ b/packages/@vuepress/markdown/__tests__/fragments/code-snippet.md @@ -1 +1 @@ -<<< @/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) From 8de126f70c5a5648f743e20db2e890a869aa9438 Mon Sep 17 00:00:00 2001 From: Billyyyyy3320 Date: Fri, 19 Feb 2021 00:02:21 +0800 Subject: [PATCH 2/2] test($markdown): add unit test for importing path with file extention --- .../markdown/__tests__/__snapshots__/snippet.spec.js.snap | 4 ++++ .../@vuepress/markdown/__tests__/fragments/code-snippet.md | 2 ++ 2 files changed, 6 insertions(+) diff --git a/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap b/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap index 6c7453b2f0..19cc4ef9f2 100644 --- a/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap +++ b/packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap @@ -1,6 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`snippet import snippet 1`] = ` +
export default function () {
+  // ..
+}
+
# 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 0a434f0d74..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