Skip to content

Commit

Permalink
fix: single backtick rendering as a codeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikmurakonda committed Oct 5, 2023
1 parent 930f71a commit 738341b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions components/MDX.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function getMDXComponents() {
th: props => <th {...props} className={`${props.className || ''} px-6 py-3 border-b border-gray-200 bg-gray-100 text-left text-xs leading-4 font-medium font-body text-gray-900 uppercase tracking-wider`} />,
tr: props => <tr {...props} className={`${props.className || ''} bg-white`} />,
td: props => <td {...props} className={`${props.className || ''} px-6 py-4 border-b border-gray-200 text-sm leading-5 text-gray-700 tracking-tight`} />,
pre: CodeComponent,
pre: PreComponent,
code: props => <code {...props} className={`${props.className || ''} px-1 py-0.5 bg-gray-200 text-gray-800 rounded font-mono text-sm`} />,
hr: props => <hr {...props} className={`${props.className || ''} my-8`} />,
CodeBlock,
Expand Down Expand Up @@ -91,11 +91,16 @@ export function getMDXComponents() {
}
}

function CodeComponent({ children, className, ...rest }) {
if (!children || !children.props || !children.type || children.type.name !== 'code') return <pre {...rest} className={`${className || ''} my-8`} />
let metastring = children.props.metastring || ''
className= children.props.className || ''
children = children.props.children
function PreComponent(props){
if (props.children && props.children.type.name === 'code'){
return CodeComponent(props.children.props)
}
return (
<div {...props} className={`${props.className || ''} my-8`} />
)
}

function CodeComponent({ children, className = '', metastring = '', ...rest }) {
let caption
const meta = metastring.split(/([\w]+=[\w\d\s\-_:><.]+)/) || []
meta.forEach(str => {
Expand Down

0 comments on commit 738341b

Please sign in to comment.