Skip to content
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

Content Model: Keep image port if exist #2226

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ export const imageProcessor: ElementProcessor<HTMLImageElement> = (group, elemen
stackFormat(context, { segment: 'shallowClone' }, () => {
const imageFormat: ContentModelImageFormat = context.segmentFormat;

// Use getAttribute('src') instead of retrieving src directly, in case the src has port and may be stripped by browser
const src = element.getAttribute('src') ?? '';

parseFormat(element, context.formatParsers.segment, imageFormat, context);
parseFormat(element, context.formatParsers.image, imageFormat, context);
parseFormat(element, context.formatParsers.block, context.blockFormat, context);

const image = createImage(element.src, imageFormat);
const image = createImage(src, imageFormat);
const alt = element.alt;
const title = element.title;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ describe('imageProcessor', () => {
});
});

it('Image with src and port', () => {
const doc = createContentModelDocument();
const img = document.createElement('img');

img.src = 'http://test.com:80/testSrc';

imageProcessor(doc, img, context);

expect(doc).toEqual({
blockGroupType: 'Document',
blocks: [
{
blockType: 'Paragraph',
format: {},
isImplicit: true,
segments: [
{
segmentType: 'Image',
format: {},
src: 'http://test.com:80/testSrc',
dataset: {},
},
],
},
],
});
});

it('Image with regular selection', () => {
const doc = createContentModelDocument();
const img = document.createElement('img');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ describe('wordOnlineHandler', () => {
segments: [
{
segmentType: 'Image',
src: 'http://www.microsoft.com/',
src: 'http://www.microsoft.com',
format: {
letterSpacing: 'normal',
fontFamily:
Expand Down
Loading