@@ -12,7 +12,7 @@ import { StrictDict } from '../../utils';
12
12
import pluginConfig from './pluginConfig' ;
13
13
import * as module from './hooks' ;
14
14
import tinyMCE from '../../data/constants/tinyMCE' ;
15
- import { getRelativeUrl , getStaticUrl } from './utils' ;
15
+ import { getRelativeUrl , getStaticUrl , parseAssetName } from './utils' ;
16
16
17
17
export const state = StrictDict ( {
18
18
// eslint-disable-next-line react-hooks/rules-of-hooks
@@ -89,9 +89,9 @@ export const replaceStaticWithAsset = ({
89
89
const isStatic = src . startsWith ( '/static/' ) ;
90
90
const assetSrc = src . substring ( 0 , src . indexOf ( '"' ) ) ;
91
91
const staticName = assetSrc . substring ( 8 ) ;
92
- const assetName = assetSrc . replace ( / \/ a s s e t s \/ . + [ ^ / ] \/ / g , '' ) ;
92
+ const assetName = parseAssetName ( src ) ;
93
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 ;
94
+ const isCorrectAssetFormat = assetSrc . startsWith ( '/asset' ) && assetSrc . match ( / \/ a s s e t - v 1 : \S + [ + ] \S + [ @ ] \S + [ + ] \S + [ @ ] / g) ?. length >= 1 ;
95
95
// assets in expandable text areas so not support relative urls so all assets must have the lms
96
96
// endpoint prepended to the relative url
97
97
if ( editorType === 'expandable' ) {
@@ -407,15 +407,7 @@ export const setAssetToStaticUrl = ({ editorValue, lmsEndpointUrl }) => {
407
407
408
408
const assetSrcs = typeof content === 'string' ? 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) : [ ] ;
409
409
assetSrcs . filter ( src => src . startsWith ( '/asset' ) ) . forEach ( src => {
410
- let nameFromEditorSrc ;
411
- if ( src . match ( / \/ a s s e t - v 1 : \S + [ + ] \S + [ @ ] \S + [ + ] \S + \/ \w / ) ?. length >= 1 ) {
412
- const assetBlockName = src . substring ( 0 , src . search ( / ( " | & q u o t ; ) / ) ) ;
413
- const dividedSrc = assetBlockName . split ( / \/ a s s e t - v 1 : \S + [ + ] \S + [ @ ] \S + [ + ] \S + \/ / ) ;
414
- [ , nameFromEditorSrc ] = dividedSrc ;
415
- } else {
416
- const assetBlockName = src . substring ( src . indexOf ( '@' ) + 1 , src . search ( / ( " | & q u o t ; ) / ) ) ;
417
- nameFromEditorSrc = assetBlockName . substring ( assetBlockName . indexOf ( '@' ) + 1 ) ;
418
- }
410
+ const nameFromEditorSrc = parseAssetName ( src ) ;
419
411
const portableUrl = getStaticUrl ( { displayName : nameFromEditorSrc } ) ;
420
412
const currentSrc = src . substring ( 0 , src . search ( / ( " | & q u o t ; ) / ) ) ;
421
413
const updatedContent = content . replace ( currentSrc , portableUrl ) ;
0 commit comments