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): use non-greedy matching when parsing attributes #1469

Merged
merged 2 commits into from
Jan 24, 2024
Merged

fix(markdown): use non-greedy matching when parsing attributes #1469

merged 2 commits into from
Jan 24, 2024

Conversation

pengzhanbo
Copy link
Member

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Provide a description in this PR that addresses what the PR is solving. If this PR is going to solve an existing issue, please reference the issue (e.g. close #123).

What is the purpose of this pull request?

  • Bug fix
  • New feature
  • Documentation update
  • Other

Description

When parsing code attrs, due to the greedy matching adopted in the current regular expression, the result of matching will be matched to the content that does not belong to it when there are multiple attrs.

```ts title="config/index.ts" foo="foo"
// more
```
const title = resolveAttr(info, 'title')
console.log(title)  // output -> config/index.ts" foo="foo

Modify the regular expression:

- const pattern = `\\b${attr}\\s*=\\s*(?<quote>['"])(?<content>.+)\\k<quote>(\\s|$)`
+ const pattern = `\\b${attr}\\s*=\\s*(?<quote>['"])(?<content>.+?)\\k<quote>(\\s|$)`

Result:

const title = resolveAttr(info, 'title')
console.log(title)  // output -> config/index.ts

close #1277 #1456

Screenshots

Before

After

@Mister-Hope
Copy link
Member

try to fix the ci?

@meteorlxy meteorlxy changed the title fix(markdown): attribute parse should be non-greedy matching fix(markdown): use non-greedy matching when parsing attributes Jan 24, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 7637598102

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 40.781%

Totals Coverage Status
Change from base Build 7636570246: 0.0%
Covered Lines: 676
Relevant Lines: 1700

💛 - Coveralls

@meteorlxy
Copy link
Member

try to fix the ci?

@Mister-Hope I have no idea why the e2e workflow would randomly time out. Increasing the timeout config does not help. It should somehow get stuck 🤔

@meteorlxy meteorlxy merged commit 91d8e3d into vuepress:main Jan 24, 2024
33 checks passed
@meteorlxy
Copy link
Member

@pengzhanbo Thanks for your contributions! ❤️

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.

Add title support for code blocks
4 participants