@@ -77,38 +77,40 @@ export const replaceStaticWithAsset = ({
77
77
lmsEndpointUrl,
78
78
} ) => {
79
79
let content = initialContent ;
80
+ let hasChanges = false ;
80
81
const srcs = content . split ( / ( s r c = " | s r c = & q u o t ; | h r e f = " | h r e f = & q u o t ) / g) . filter (
81
82
src => src . startsWith ( '/static' ) || src . startsWith ( '/asset' ) ,
82
83
) ;
83
- if ( isEmpty ( srcs ) ) {
84
- return initialContent ;
85
- }
86
- srcs . forEach ( src => {
87
- const currentContent = content ;
88
- let staticFullUrl ;
89
- const isStatic = src . startsWith ( '/static/' ) ;
90
- const assetSrc = src . substring ( 0 , src . indexOf ( '"' ) ) ;
91
- const staticName = assetSrc . substring ( 8 ) ;
92
- const assetName = assetSrc . replace ( / \/ a s s e t s \/ .+ [ ^ / ] \/ / g, '' ) ;
93
- const displayName = isStatic ? staticName : assetName ;
94
- const isCorrectAssetFormat = assetSrc . match ( / \/ a s s e t - v 1 : \S + [ + ] \S + [ @ ] \S + [ + ] \S + [ @ ] / g) ?. length >= 1 ;
95
- // assets in expandable text areas so not support relative urls so all assets must have the lms
96
- // endpoint prepended to the relative url
97
- if ( editorType === 'expandable' ) {
98
- if ( isCorrectAssetFormat ) {
99
- staticFullUrl = `${ lmsEndpointUrl } ${ assetSrc } ` ;
100
- } else {
101
- staticFullUrl = `${ lmsEndpointUrl } ${ getRelativeUrl ( { courseId : learningContextId , displayName } ) } ` ;
84
+ if ( ! isEmpty ( srcs ) ) {
85
+ srcs . forEach ( src => {
86
+ const currentContent = content ;
87
+ let staticFullUrl ;
88
+ const isStatic = src . startsWith ( '/static/' ) ;
89
+ const assetSrc = src . substring ( 0 , src . indexOf ( '"' ) ) ;
90
+ const staticName = assetSrc . substring ( 8 ) ;
91
+ const assetName = assetSrc . replace ( / \/ a s s e t s \/ .+ [ ^ / ] \/ / g, '' ) ;
92
+ const displayName = isStatic ? staticName : assetName ;
93
+ const isCorrectAssetFormat = assetSrc . match ( / \/ a s s e t - v 1 : \S + [ + ] \S + [ @ ] \S + [ + ] \S + [ @ ] / g) ?. length >= 1 ;
94
+ // assets in expandable text areas so not support relative urls so all assets must have the lms
95
+ // endpoint prepended to the relative url
96
+ if ( editorType === 'expandable' ) {
97
+ if ( isCorrectAssetFormat ) {
98
+ staticFullUrl = `${ lmsEndpointUrl } ${ assetSrc } ` ;
99
+ } else {
100
+ staticFullUrl = `${ lmsEndpointUrl } ${ getRelativeUrl ( { courseId : learningContextId , displayName } ) } ` ;
101
+ }
102
+ } else if ( ! isCorrectAssetFormat ) {
103
+ staticFullUrl = getRelativeUrl ( { courseId : learningContextId , displayName } ) ;
102
104
}
103
- } else if ( ! isCorrectAssetFormat ) {
104
- staticFullUrl = getRelativeUrl ( { courseId : learningContextId , displayName } ) ;
105
- }
106
- if ( staticFullUrl ) {
107
- const currentSrc = src . substring ( 0 , src . indexOf ( '"' ) ) ;
108
- content = currentContent . replace ( currentSrc , staticFullUrl ) ;
109
- }
110
- } ) ;
111
- return content ;
105
+ if ( staticFullUrl ) {
106
+ const currentSrc = src . substring ( 0 , src . indexOf ( '"' ) ) ;
107
+ content = currentContent . replace ( currentSrc , staticFullUrl ) ;
108
+ hasChanges = true ;
109
+ }
110
+ } ) ;
111
+ if ( hasChanges ) { return content ; }
112
+ }
113
+ return false ;
112
114
} ;
113
115
114
116
export const getImageResizeHandler = ( { editor, imagesRef, setImage } ) => ( ) => {
@@ -196,7 +198,7 @@ export const setupCustomBehavior = ({
196
198
lmsEndpointUrl,
197
199
learningContextId,
198
200
} ) ;
199
- updateContent ( newContent ) ;
201
+ if ( newContent ) { updateContent ( newContent ) ; }
200
202
} ) ;
201
203
}
202
204
editor . on ( 'ExecCommand' , ( e ) => {
@@ -206,7 +208,7 @@ export const setupCustomBehavior = ({
206
208
initialContent,
207
209
learningContextId,
208
210
} ) ;
209
- editor . setContent ( newContent ) ;
211
+ if ( newContent ) { editor . setContent ( newContent ) ; }
210
212
}
211
213
if ( e . command === 'RemoveFormat' ) {
212
214
editor . formatter . remove ( 'blockquote' ) ;
0 commit comments