Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix($markdown): support path without file extension when importing code snippets #2677

Merged
merged 2 commits into from Feb 18, 2021

Conversation

mitjat
Copy link
Contributor

@mitjat mitjat commented Oct 23, 2020

Summary

This PR fixes an issue where code snippets in markdown can reference a filename to include only if the filename has an extension.

For example, including a snippet like this:

<<< @/path/to/Dockerfile

(note the path does not contain a .) results in the snippet being rendered as the string Invalid code snippet option even if the target file exists.

The bug is caused by an overly restrictive regex that demands at least one literal . in the include path. This PR fixes the regex and adds a test case.

My personal preference would be to refactor the relatively large regex into simpler parsing steps, but I don't want to mess with it and inadvertently introduce subtle side effects :/

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

If changing the UI of default theme, please provide the before/after screenshot: N/A

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications: N/A

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome
  • Firefox
  • Safari
  • Edge
  • IE

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

@mitjat
Copy link
Contributor Author

mitjat commented Nov 3, 2020

@kefranabg care to take a look when you have some time? I see you were the most recent reviewer for this module. Thanks!

@mitjat mitjat changed the title fix($markdown): accept snippet paths with no extension fix($markdown): allow snippets to come from filenames with no dots Feb 16, 2021
@@ -1 +1 @@
<<< @/packages/@vuepress/markdown/__tests__/fragments/snippet.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep it, it would make sure import path with file extension works fine

Copy link
Collaborator

@billyyyyy3320 billyyyyy3320 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review. Thanks

@billyyyyy3320 billyyyyy3320 changed the title fix($markdown): allow snippets to come from filenames with no dots fix($markdown): support path without file extension when importing code snippets Feb 18, 2021
@billyyyyy3320 billyyyyy3320 merged commit bb4ae4e into vuejs:master Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants