refactor(v2): improve regex matching code-block title (#3685)

This commit is contained in:
Anh Hong 2020-11-05 18:33:08 +07:00 committed by GitHub
parent 7c7e0c24f6
commit f8a6b391cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -84,7 +84,7 @@ const highlightDirectiveRegex = (lang) => {
return getHighlightDirectiveRegex();
}
};
const codeBlockTitleRegex = /title=".*"/;
const codeBlockTitleRegex = /(?:title=")(.*)(?:")/;
export default ({
children,
@ -125,9 +125,7 @@ export default ({
// Tested above
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
codeBlockTitle = metastring
.match(codeBlockTitleRegex)![0]
.split('title=')[1]
.replace(/"+/g, '');
.match(codeBlockTitleRegex)![1];
}
let language =