mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-15 10:07:33 +02:00
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>
This commit is contained in:
parent
8119de105a
commit
1abadbaeca
4 changed files with 71 additions and 9 deletions
12
packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts
Normal file
12
packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* 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] ?? '';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue