Skip to content

Commit f691d42

Browse files
authored
feat(title): make it possible to specify the title (#14)
* feat(title): make it possible to specify the title * chore(example): provide title example
1 parent 50d7729 commit f691d42

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

example/docs/doc1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ This theme provides the following:
1111
https://github.com/saucelabs/docusaurus-theme-github-codeblock/blob/main/src/theme/ReferenceCodeBlock/index.tsx#L104-L107
1212
```
1313

14+
```js reference title="Custom Title"
15+
https://github.com/saucelabs/docusaurus-theme-github-codeblock/blob/main/src/theme/ReferenceCodeBlock/index.tsx#L104-L107
16+
```
17+
1418
You can write content using [GitHub-flavored Markdown syntax](https://github.github.com/gfm/).
1519

1620
## Markdown Syntax

src/theme/ReferenceCodeBlock/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,15 @@ function ReferenceCode(props: ReferenceCodeBlockProps) {
109109
fetchCode(codeSnippetDetails, fetchResultStateDispatcher)
110110
}
111111

112+
const titleMatch = props.metastring?.match(/title="(?<title>.*)"/);
113+
112114
const customProps = {
113115
...props,
114-
metastring: ` title="${codeSnippetDetails.title}"`,
115-
children: initialFetchResultState.code
116-
}
116+
metastring: titleMatch?.groups?.title
117+
? ` title="${titleMatch?.groups?.title}"`
118+
: ` title="${codeSnippetDetails.title}"`,
119+
children: initialFetchResultState.code,
120+
};
117121

118122
return (
119123
<div>

0 commit comments

Comments
 (0)