mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-15 10:07:33 +02:00
feat(theme-classic): usable CodeBlock outside markdown (#6216)
This commit is contained in:
parent
96dbb8e7ef
commit
c45281a581
5 changed files with 53 additions and 18 deletions
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import rangeParser from 'parse-numeric-range';
|
||||
import type {Language} from 'prism-react-renderer';
|
||||
|
||||
const codeBlockTitleRegex = /title=(["'])(.*?)\1/;
|
||||
const highlightLinesRangeRegex = /{([\d,-]+)}/;
|
||||
|
@ -93,11 +92,11 @@ export function parseCodeBlockTitle(metastring?: string): string {
|
|||
return metastring?.match(codeBlockTitleRegex)?.[2] ?? '';
|
||||
}
|
||||
|
||||
export function parseLanguage(className?: string): Language | undefined {
|
||||
export function parseLanguage(className: string): string | undefined {
|
||||
const languageClassName = className
|
||||
?.split(' ')
|
||||
.split(' ')
|
||||
.find((str) => str.startsWith('language-'));
|
||||
return languageClassName?.replace(/language-/, '') as Language | undefined;
|
||||
return languageClassName?.replace(/language-/, '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +106,7 @@ export function parseLanguage(className?: string): Language | undefined {
|
|||
export function parseLines(
|
||||
content: string,
|
||||
metastring?: string,
|
||||
language?: Language,
|
||||
language?: string,
|
||||
): {
|
||||
highlightLines: number[];
|
||||
code: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue