docusaurus/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts
duanwilliam 1abadbaeca
fix(v2): fix code block title parsing, support multiple metastring attributes (#4541)
* feat: lazy match classic theme code block title

* feat: allow single quotes for classic theme code block title

* refactor(v2): extract parseCodeBlockTitle function

extract `parseCodeBlockTitle` function to add tests for title parsing

* test(v2): add tests for parseCodeBlockTitle

* move code block title parser to theme-common

Co-authored-by: slorber <lorber.sebastien@gmail.com>
2021-04-14 10:24:52 +02:00

12 lines
371 B
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const codeBlockTitleRegex = /title=(["'])(.*?)\1/;
export function parseCodeBlockTitle(metastring?: string): string {
return metastring?.match(codeBlockTitleRegex)?.[2] ?? '';
}