diff --git a/src/editors/data/services/cms/utils.js b/src/editors/data/services/cms/utils.js index a16318aee..323543474 100644 --- a/src/editors/data/services/cms/utils.js +++ b/src/editors/data/services/cms/utils.js @@ -23,6 +23,16 @@ export const deleteObject = (...args) => getAuthenticatedHttpClient().delete(... export const client = getAuthenticatedHttpClient; +/** + * Replaces all relative image URLs in the given text with absolute URLs. + * + * This function searches for relative URLs in `src` attributes of image tags within the provided text, + * and replaces them with absolute URLs by prefixing them with the specified LMS endpoint URL. + * + * @param {string} text - The input text containing image tags with relative URLs. + * @param {string} lmsEndpointUrl - The base URL to prepend to each relative URL to form an absolute URL. + * @returns {string} The text with all relative image URLs replaced by absolute URLs. + */ export const replaceRelativeImageUrlsByAbsolute = (text, lmsEndpointUrl) => { const relativeSrcRegExp = /(?<=src=")(\/.*?)(?=")/g; const replaceRelativeToAbsoluteUrl = (relativeUrl) => `${lmsEndpointUrl}${relativeUrl}`;