feat(theme-classic): usable CodeBlock outside markdown (#6216)

This commit is contained in:
Joshua Chen 2021-12-30 00:17:09 +08:00 committed by GitHub
parent 96dbb8e7ef
commit c45281a581
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 18 deletions

View file

@ -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;