Skip to content

Commit

Permalink
fix(markdown): attribute parse should be non-greedy matching
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Jan 23, 2024
1 parent 49f6f48 commit 0d757a5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/markdown/src/plugins/codePlugin/resolveAttr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
export const resolveAttr = (info: string, attr: string): string | null => {
// try to match specified attr mark
const pattern = `\\b${attr}\\s*=\\s*(?<quote>['"])(?<content>.+)\\k<quote>(\\s|$)`
const pattern = `\\b${attr}\\s*=\\s*(?<quote>['"])(?<content>.+?)\\k<quote>(\\s|$)`
const regex = new RegExp(pattern, 'i')
const match = info.match(regex)

Expand Down
4 changes: 2 additions & 2 deletions packages/markdown/tests/plugins/codePlugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function bar () {
}
${codeFence}
${codeFence}ts title="config/foo.ts" {1,2-4,5-5}
${codeFence}ts title="config/foo.ts" foo="foo" {1,2-4,5-5}
const foo = 'foo'
function bar () {
Expand Down Expand Up @@ -198,7 +198,7 @@ function bar () {
}
${codeFence}
${codeFence}ts title="config/foo.ts" {1,2}:no-line-numbers
${codeFence}ts title="config/foo.ts" foo="foo" {1,2}:no-line-numbers
const foo = 'foo'
function bar () {
Expand Down

0 comments on commit 0d757a5

Please sign in to comment.