From 8dc1a3f8be4f41a241cc8cf53e6752b4d9d0add5 Mon Sep 17 00:00:00 2001 From: ihor-romaniuk Date: Thu, 30 May 2024 15:52:52 +0200 Subject: [PATCH] docs: add JS docs --- src/editors/data/services/cms/utils.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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}`;