OK, I have similar issues with SharePoint, but What i found was the following.
- Image URL Handling: SharePoint Online sometimes has issues with external image URLs. Ensure that the images are stored within the same SharePoint site collection to avoid cross-domain issues.
- Permissions: Double-check that the images have the correct permissions. Even if the URLs are valid, the images might not be visible if the permissions are not set correctly. Make sure the images are published and accessible to all users who need to view the page.
- HTML Sanitization: SharePoint Online might be sanitizing the HTML content when you switch to edit mode, which can strip out certain tags, including
<img>
. This is a security feature to prevent malicious code. - Alternative Methods: Instead of embedding images directly in the HTML, consider using the Image web part or the Embed web part to add images. These methods are more reliable and supported by SharePoint Online.
- PnP PowerShell: Ensure that the PnP PowerShell command is correctly formatting the HTML content. Sometimes, special characters or encoding issues can cause problems.
I found this little tip I think might help.
Here's a revised approach using the Image web part:
# Add an image web part to the page
Add-PnPClientSideWebPart -Page "MyTestPage" -DefaultWebPartType Image -WebPartProperties @{
"ImageUrl" = "https://mymigrationsiteurl/sites/migration/images/image1.jpg"
"AltText" = "Description of the image"
}
This method ensures that the image is added using a supported web part, which should prevent it from disappearing when editing the page.
I hope something in here helps.