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