interface MetaData { [ key ] : string ; } type MarkdownMetaDataReturn = [ RegExpExecArray , MetaData ] ; export function useMarkdownMetaData ( text ) { return React . useMemo < MarkdownMetaDataReturn > ( ( ) => { const metaData = { } ; const metaRegExp = RegExp ( /^---[\r\n](((?!---).|[\r\n])*)[\r\n]---$/m ) ; const rawMetaData = metaRegExp . exec ( text ) ; let keyValues ; if ( rawMetaData !== null ) { keyValues = rawMetaData [ 1 ] . split ( '\n' ) ; keyValues . forEach ( ( keyValue ) => { const [ , key , value ] = keyValue . split ( /(.+): (.+)/ ) ; metaData [ key ] = value . trim ( ) ; } ) ; } return [ rawMetaData , metaData ] ; } , [ text ] ) ; }