@@ -33,6 +33,12 @@ class TuiEditor extends React.Component {
3333 this . editorInst . off ( eventName )
3434 this . editorInst . on ( eventName , props [ key ] )
3535 } )
36+
37+ // always add `https` to the links if link was added without `http` or `https`
38+ this . editorInst . on ( 'convertorAfterHtmlToMarkdownConverted' , ( inputMarkdown ) => {
39+ const outputMarkdown = inputMarkdown . replace ( / \[ ( [ ^ \] ] * ) \] \( (? ! h t t p s ? ) ( [ ^ ) ] + ) \) / g, '[$1](https://$2)' )
40+ return outputMarkdown
41+ } )
3642 }
3743
3844 componentDidMount ( ) {
@@ -47,6 +53,17 @@ class TuiEditor extends React.Component {
4753 this . bindEventHandlers ( props )
4854 }
4955
56+ componentWillUnmount ( ) {
57+ Object . keys ( this . props )
58+ . filter ( ( key ) => / ^ o n [ A - Z ] [ a - z A - Z ] + / . test ( key ) )
59+ . forEach ( ( key ) => {
60+ const eventName = key [ 2 ] . toLowerCase ( ) + key . slice ( 3 )
61+ this . editorInst . off ( eventName )
62+ } )
63+
64+ this . editorInst . off ( 'convertorAfterHtmlToMarkdownConverted' )
65+ }
66+
5067 handleValueChange ( ) {
5168 if ( this . props . onChange ) {
5269 this . props . onChange ( this . getInstance ( ) . getMarkdown ( ) )
@@ -68,7 +85,11 @@ class TuiEditor extends React.Component {
6885 if ( this . props . className !== className ) {
6986 return true
7087 }
71- // this.bindEventHandlers(nextProps, this.props)
88+
89+ // this looks like a bed idea to re-subscribe all the event on each re-render
90+ // also, note, that we had to disable this.editorInst.off(eventName);
91+ // otherwise popup for choosing Headings never closes
92+ // this.bindEventHandlers(nextProps, this.props);
7293
7394 return false
7495 }
0 commit comments