import SETTINGS from "../../../common/Settings" ; declare namespace marked { function parse ( md , options ) ; } export default class DFChatEditor extends FormApplication { private chatMessage : ChatMessage ; public static readonly PREF_MARKDOWN = 'edit-markdown' ; returns @override
     *  see Application . defaultOptions static get defaultOptions ( ) : FormApplication . Options { return mergeObject ( FormApplication . defaultOptions as Partial < FormApplication . Options > , { closeOnSubmit : true , editable : true , resizable : true , width : 400 , popOut : true , title : 'DF_CHAT_EDIT.Editor_Title' , template : 'modules/df-chat-enhance/templates/chat-edit.hbs' } ) as FormApplication . Options ; } constructor ( chatMessage ) { super ( { } ) ; this . chatMessage = chatMessage ; } @override  getData ( options ? ) { return mergeObject ( options , { messageText : this . chatMessage . data . content . replace ( /< *br *\/?>/gm , '\n' ) . replace ( /<p +class="df-edited">.+/ , '' ) } ) ; } @override  activateListeners ( html ) { super . activateListeners ( html ) ; html . find ( '#cancel' ) . on ( 'click' , async ( ) => await this . close ( ) ) ; } @override  async _updateObject ( _event ? , formData ? ) { let data = formData . content as string ; if ( SETTINGS . get ( DFChatEditor . PREF_MARKDOWN ) ) { data = DFChatEditor . processMarkdown ( data ) [ 1 ] ; } else { data = data . replace ( /\r?\n/gm , '<br/>' ) ; } if ( data . search ( /<p +class="df-edited">/ ) < 0 ) { data += `<p class="df-edited">${ 'DF_CHAT_EDIT.EditedFlag' . localize ( ) }</p>` ; } this . chatMessage . update ( { content : data } ) ; } @override  close ( options ? ) { delete ( < any > this . chatMessage ) . chatEditor ; return super . close ( options ) ; } public static processMarkdown ( message ) { const originalMessage = message ; message = marked . parse ( message , { headerIds : false , breaks : true } ) . trimEnd ( ) ; if ( message . startsWith ( '<p>' ) ) message = message . substr ( 3 ) ; if ( message . endsWith ( '</p>' ) ) message = message . substr ( 0 , message . length - 4 ) ; const newLine = /(<\/?[ a-z]+>)\n(<\/?[ a-z]+>?)/ ; while ( newLine . test ( message ) ) message = message . replace ( newLine , '$1$2' ) ; return [ originalMessage , message ] ; } }