test02/node_modules/@vuepress/plugin-prismjs/lib/node/utils/resolveAttr.js
罗佳鸿 6aa1ebe342
Some checks are pending
部署文档 / deploy-gh-pages (push) Waiting to run
first commit
2024-08-13 10:11:19 +08:00

12 lines
416 B
JavaScript

/**
* Resolve the specified attribute from token info
*/
export const resolveAttr = (info, attr) => {
// try to match specified attr mark
const pattern = `\\b${attr}\\s*=\\s*(?<quote>['"])(?<content>.+?)\\k<quote>(\\s|$)`;
const regex = new RegExp(pattern, 'i');
const match = info.match(regex);
// return content if matched, null if not specified
return match?.groups?.content ?? null;
};