Skip to content

Commit

Permalink
docs: add JS docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-romaniuk committed May 30, 2024
1 parent 874eef3 commit 8dc1a3f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/editors/data/services/cms/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down

0 comments on commit 8dc1a3f

Please sign in to comment.