@@ -23,6 +23,7 @@ import {PatternVariantFontMatter, PatternFrontMatter} from '../../types';
2323import PageMeta from '../PageMeta' ;
2424import { Stack , Row } from '../Stack' ;
2525import { Box } from '../Box' ;
26+ import Code from '../Code' ;
2627import { Lede } from '../Lede' ;
2728import { Heading } from '../Heading' ;
2829import PatternsExample from '../PatternsExample' ;
@@ -60,10 +61,17 @@ function codeAsContext(): Plugin {
6061 meta : Record < string , any > ;
6162 } [ ] = [ ] ;
6263 visit ( tree , 'code' , ( node , index , parent ) => {
63- try {
64- codes . push ( { node, index : index ! , parent, meta : JSON . parse ( node . meta ) } ) ;
65- } catch ( error ) {
66- // Just ignore this block
64+ if ( node . meta ) {
65+ try {
66+ codes . push ( {
67+ node,
68+ index : index ! ,
69+ parent,
70+ meta : JSON . parse ( node . meta ) ,
71+ } ) ;
72+ } catch ( error ) {
73+ // Just ignore this block
74+ }
6775 }
6876 } ) ;
6977
@@ -263,7 +271,7 @@ const BaseMarkdown = ({
263271 < Image fill src = { src } alt = { alt ?? '' } />
264272 </ div >
265273 ) : null ,
266- code : function Code ( {
274+ code : function MdCode ( {
267275 inline,
268276 // @ts -expect-error Unsure how to tell react-markdown this prop is
269277 // being injected by a plugin
@@ -301,7 +309,9 @@ const BaseMarkdown = ({
301309 ) ;
302310 }
303311
304- return < code > { ( children ?. [ 0 ] as string ) ?? '' } </ code > ;
312+ return (
313+ < Code code = { { title : '' , code : ( children ?. [ 0 ] as string ) ?? '' } } />
314+ ) ;
305315 } ,
306316 ...components ,
307317 } }
0 commit comments