Skip to content

Commit

Permalink
chore: improve regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Dec 29, 2023
1 parent f164198 commit 67fcb7a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/markdown/src/plugins/codePlugin/resolveAttr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*/
export const resolveAttr = (info: string, attr: string): string | null => {
// try to match specified attr mark
const pattern = `\\b${attr}\\s*=\\s*['"](?<title>.+)['"](\\s|$)`
const pattern = `\\b${attr}\\s*=\\s*(?<quote>['"])(?<content>.+)\\k<quote>(\\s|$)`
const regex = new RegExp(pattern, 'i')
const match = info.match(regex)

// return title if matched, null if not specified
return match?.groups?.title ?? null
// return content if matched, null if not specified
return match?.groups?.content ?? null
}

0 comments on commit 67fcb7a

Please sign in to comment.