Skip to content

Commit 5d7bf9b

Browse files
committed
fix theme styles after using scpoed md styles
1 parent 141c2ce commit 5d7bf9b

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

packages/theme-doc/src/Layout/FileText/index.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import CodeBlock from '../MDX/CodeBlock'
55
export interface Props {
66
syntax: Language
77
text: string
8+
className?: string
89
}
910

10-
export function FileText({ syntax, text }: Props) {
11+
export function FileText({ syntax, text, className }: Props) {
1112
if (typeof text !== 'string') {
1213
return (
1314
<pre>{`FileText Error: <FileText> component receives invalid props.
@@ -16,5 +17,11 @@ If you use it in markdown, you should use it exactly like "<FileText src="./file
1617
`}</pre>
1718
)
1819
}
19-
return <CodeBlock className={`language-${syntax}`} children={text} />
20+
21+
return (
22+
<CodeBlock
23+
className={[`language-${syntax}`, className].filter(Boolean).join(' ')}
24+
children={text}
25+
/>
26+
)
2027
}

packages/theme-doc/src/Layout/MDX/index.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const components: MDXComponents = {
4040
}),
4141
CodeBlock,
4242
Demo,
43-
TsInfo,
44-
FileText,
43+
TsInfo: withMdClassName(TsInfo),
44+
FileText: withMdClassName(FileText),
4545
a: (props: React.HTMLProps<HTMLAnchorElement>) => {
4646
const { href, ...rest } = props
4747
if (href?.startsWith('/')) {
@@ -117,13 +117,13 @@ const MDX: React.FC<React.PropsWithChildren<any>> = ({ children }) => {
117117
export default MDX
118118

119119
/**
120-
* Only "FlowContent" elements need to have .markdown-el className
121-
* because they are top-level elements under the root
122-
* https://github.com/syntax-tree/mdast#flowcontent
123-
*
120+
* We only need to add ".markdown-el" className to top-level block elements under the markdown root.
124121
* our github-markdown-light.css will add markdown style to markdown-el and all its descendants
122+
*
123+
* Ref: "FlowContent" are the top-level block elements in mdast
124+
* https://github.com/syntax-tree/mdast#flowcontent
125125
*/
126-
function withMdClassName(Component: React.FC | string) {
126+
function withMdClassName(Component: React.FC<any> | string) {
127127
return function (props: any) {
128128
const { className } = props
129129
const newClassName = className ? `${className} markdown-el` : 'markdown-el'

packages/theme-doc/src/Layout/TsInfo/index.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import s from './index.module.css'
55

66
interface Props {
77
data: TsInfoData
8+
className?: string
89
}
910

10-
export function TsInfo({ data }: Props) {
11+
export function TsInfo({ data, className: _className }: Props) {
12+
const className = [_className, s.table].filter(Boolean).join(' ')
13+
1114
if (data.type === 'interface' || data.type === 'object-literal') {
1215
return (
13-
<table className={s.table}>
16+
<table className={className}>
1417
<thead>
1518
<tr>
1619
<th>Name</th>
@@ -47,7 +50,7 @@ export function TsInfo({ data }: Props) {
4750

4851
if (data.type === 'other') {
4952
return (
50-
<table className={s.table}>
53+
<table className={className}>
5154
<thead>
5255
<tr>
5356
<th>Name</th>

0 commit comments

Comments
 (0)