import emojiData from 'markdown-it-emoji/lib/data/full.json' ; const parseEmojis = ( str ) => { return str . replace ( /:(.+?):/g , ( placeholder , key ) => emojiData [ key ] || placeholder ) ; } ; const unescapeHtml = ( html ) => html . replace ( /&quot;/g , '"' ) . replace ( /&#39;/g , "'" ) . replace ( /&#x3A;/g , ':' ) . replace ( /&lt;/g , '<' ) . replace ( /&gt;/g , '>' ) ; const removeMarkdownTokens = ( str ) => str . replace ( /(\[(.[^\]]+)\]\((.[^)]+)\))/g , '$2' ) . replace ( /(`|\*{1,3}|_)(.*?[^\\])\1/g , '$2' ) . replace ( /(\\)(\*|_|`|\!|<|\$)/g , '$2' ) ; const remvoeCustomAnchor = ( str ) => str . replace ( /\{#([a-z0-9\-_]+?)\}\s*$/ , '' ) ; const trim = ( str ) => str . trim ( ) ; export const removeNonCodeWrappedHTML = ( str ) => { return String ( str ) . replace ( /(^|[^><`\\])<.*>([^><`]|$)/g , '$1$2' ) ; } ; const compose = ( ... processors ) => { if ( processors . length === 0 ) return ( input ) => input ; if ( processors . length === 1 ) return processors [ 0 ] ; return processors . reduce ( ( prev , next ) => { return ( str ) => next ( prev ( str ) ) ; } ) ; } ; export const parseHeader = compose ( unescapeHtml , parseEmojis , remvoeCustomAnchor , removeMarkdownTokens , trim ) ; export const deeplyParseHeader = compose ( removeNonCodeWrappedHTML , parseHeader ) ;