Skip to content

Commit 0dd7caa

Browse files
authored
PRO-8272: Resolve images (#5069)
1 parent 36667b5 commit 0dd7caa

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
* Fixes a bug in the login `uponSubmit` filter where a user could login without meeting the requirement.
1414

15+
### Fixes
16+
17+
* Resolve inline image URLs correctly when in edit mode and not in the default locale.
18+
1519
### Changes
1620

1721
* Redirects to URLs containing accent marks and other non-ascii characters now behave as expected with Astro. Pre-encoding the URLs exactly the way `res.redirect` would before passing them to Astro prevents an error in Astro and allows the redirect to succeed.

modules/@apostrophecms/rich-text-widget/ui/apos/tiptap-extensions/Image.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default options => {
5050
parseHTML: element => {
5151
const src = element.querySelector('img')?.getAttribute('src');
5252

53-
const components = src.split('/');
53+
const components = src.replace(/\?.*$/, '').split('/');
5454
if (components.length < 2) {
5555
return false;
5656
}
@@ -116,6 +116,7 @@ export default options => {
116116
},
117117

118118
renderHTML({ HTMLAttributes }) {
119+
const locale = apos.getActiveLocale();
119120
const result = [
120121
'figure',
121122
mergeAttributes(
@@ -127,7 +128,7 @@ export default options => {
127128
];
128129
// Conditionally add the link
129130
const imgAttrs = {
130-
src: `${apos.modules['@apostrophecms/image'].action}/${HTMLAttributes.imageId}/src`,
131+
src: `${apos.modules['@apostrophecms/image'].action}/${HTMLAttributes.imageId}/src?aposLocale=${locale}&aposMode=draft`,
131132
alt: HTMLAttributes.alt,
132133
draggable: false,
133134
contenteditable: false
@@ -176,6 +177,7 @@ export default options => {
176177
return ({
177178
editor, node, getPos, HTMLAttributes, decorations
178179
}) => {
180+
const locale = apos.getActiveLocale();
179181
const defaultWrapperClass = editor.isEditable
180182
? 'ProseMirror-selectednode'
181183
: '';
@@ -196,7 +198,7 @@ export default options => {
196198

197199
// Create the image element
198200
const img = document.createElement('img');
199-
img.src = `${apos.modules['@apostrophecms/image'].action}/${node.attrs.imageId}/src`;
201+
img.src = `${apos.modules['@apostrophecms/image'].action}/${node.attrs.imageId}/src?aposLocale=${locale}&aposMode=draft`;
200202
if (HTMLAttributes.alt) {
201203
img.alt = HTMLAttributes.alt;
202204
}
@@ -257,7 +259,7 @@ export default options => {
257259
}
258260
img.alt = updatedNode.attrs.alt;
259261
img.src = updatedNode.attrs.imageId
260-
? `${apos.modules['@apostrophecms/image'].action}/${updatedNode.attrs.imageId}/src`
262+
? `${apos.modules['@apostrophecms/image'].action}/${updatedNode.attrs.imageId}/src?aposLocale=${locale}&aposMode=draft`
261263
: '';
262264
figcaption.innerText = updatedNode.attrs.caption || '';
263265

0 commit comments

Comments
 (0)