import { EmojiService } from '../providers/emoji.service' ; import { MarkedOptions } from 'marked' ; import { MarkedRenderer } from 'ngx-markdown' ; description const generateEmojiRender = ( wrap , emojiService , flexLayout = false ) => ( content ) => { const regexp = /:\w+:/ ; if ( regexp . test ( content ) ) { let result ; let str = content ; const reg = /:\w+:/g ; while ( ( result = reg . exec ( content ) ) !== null ) { str = str . replace ( regexp , `<span style="${ emojiService . getStyle ( result [ 0 ] ) }"></span>` ) ; } return `<${ wrap } style="${ flexLayout ? 'display: flex; align-items: center;' : '' }">${ str }</${ wrap }>` ; } else { return `<${ wrap }>${ content }</${ wrap }>` ; } } ; description export function markedOptionsFactory ( emojiService ) { const renderer = new MarkedRenderer ( ) ; renderer . blockquote = ( text ) => { return '<blockquote class="blockquote"><p>' + text + '</p></blockquote>' ; } ; renderer . paragraph = generateEmojiRender ( 'p' , emojiService , true ) ; renderer . tablecell = generateEmojiRender ( 'td' , emojiService ) ; return { renderer : renderer , gfm : true , tables : true , breaks : true , pedantic : false , sanitize : false , smartLists : true , smartypants : false , } ; }