-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: block resize with long content and broken image path #478
Closed
ihor-romaniuk
wants to merge
3
commits into
openedx:main
from
raccoongang:romaniuk/fix/block-resize-and-broken-asset-path
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { replaceRelativeImageUrlsByAbsolute } from '../../../data/services/cms/utils'; | ||
|
||
export const preprocessProblemData = (problemData, state) => { | ||
if (problemData?.settings?.hints) { | ||
problemData.settings.hints = problemData.settings.hints.map( | ||
hint => ({ ...hint, value: replaceRelativeImageUrlsByAbsolute(hint.value, state.app.lmsEndpointUrl) }), | ||
); | ||
} | ||
|
||
if (problemData?.answers) { | ||
problemData.answers = problemData.answers.map( | ||
answer => ({ ...answer, title: replaceRelativeImageUrlsByAbsolute(answer.title, state.app.lmsEndpointUrl) }), | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,19 @@ export const post = (...args) => getAuthenticatedHttpClient().post(...args); | |
export const deleteObject = (...args) => getAuthenticatedHttpClient().delete(...args); | ||
|
||
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}`; | ||
return (text || '').replaceAll(relativeSrcRegExp, replaceRelativeToAbsoluteUrl); | ||
}; | ||
Comment on lines
+36
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment regarding |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be happening when the tinyMCE editor loads, so it is not necessary to preprocess the problem here. See https://github.com/openedx/frontend-lib-content-components/blob/main/src/editors/sharedComponents/TinyMceWidget/hooks.js#L74-L97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is not longer needed, please remove all changes related to
preprocessProblemData