Skip to content

Commit

Permalink
Merge pull request #2100 from microsoft/u/juliaroldi/link-on-images
Browse files Browse the repository at this point in the history
Fix link underline on images
  • Loading branch information
juliaroldi authored Sep 26, 2023
2 parents 897d4d2 + c5dbf33 commit 368e88e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,7 @@ export default function insertLink(
let url = (checkXss(link) || '').trim();
if (url) {
const linkData = matchLink(url);
const link: ContentModelLink = {
dataset: {},
format: {
href: linkData ? linkData.normalizedUrl : applyLinkPrefix(url),
anchorTitle,
target,
underline: true,
},
};

const linkUrl = linkData ? linkData.normalizedUrl : applyLinkPrefix(url);
const links: ContentModelLink[] = [];
let anchorNode: Node | undefined;

Expand All @@ -71,8 +62,13 @@ export default function insertLink(
originalText == text
) {
segments.forEach(x => {
const link = createLink(
linkUrl,
anchorTitle,
target,
x.segmentType == 'Text'
);
addLink(x, link);

if (x.link) {
links.push(x.link);
}
Expand All @@ -86,6 +82,7 @@ export default function insertLink(
...(getPendingFormat(editor) || {}),
});
const doc = createContentModelDocument();
const link = createLink(linkUrl, anchorTitle, target);

addLink(segment, link);
addSegment(doc, segment);
Expand Down Expand Up @@ -114,6 +111,23 @@ export default function insertLink(
}
}

const createLink = (
url: string,
anchorTitle?: string,
target?: string,
underline: boolean = true
): ContentModelLink => {
return {
dataset: {},
format: {
href: url,
anchorTitle,
target,
underline: underline,
},
};
};

// TODO: This is copied from original code. We may need to integrate this logic into matchLink() later.
function applyLinkPrefix(url: string): string {
if (!url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ describe('insertLink', () => {
format: {},
src: 'test',
dataset: {},
link,
link: {
dataset: link.dataset,
format: { ...link.format, underline: false },
},
isSelected: true,
},
{
Expand Down

0 comments on commit 368e88e

Please sign in to comment.