docs: fix code block titles (#5733)

* docs: fix code block titles

* remove console

* fix build error
This commit is contained in:
Shahed Nasser
2023-11-27 16:08:10 +00:00
committed by GitHub
parent de8f748674
commit 547b16ead5
110 changed files with 483 additions and 456 deletions

View File

@@ -34,8 +34,21 @@ export default function CodeBlock({
const CodeBlockComp =
typeof children === "string" ? StringContent : ElementContent
const title = props.title
let title = props.title
delete props.title
if (!title) {
// check if it's in `metastring` instead
if (props.metastring) {
const titleRegex = /title="?(.*)"?/
const matchedTitle = props.metastring.match(titleRegex)
if (matchedTitle?.length) {
title = matchedTitle[1].replace(/^"/, "").replace(/"$/, "")
props.metastring = props.metastring.replace(titleRegex, "")
}
}
}
return (
<div className="code-wrapper">
{title && <div className="code-header">{title}</div>}