fix(richtext-lexical): remove undefined rel and target attributes in link HTML converter (#11754)
When converting lexical to HTML, links without "open in new tab" checked were incorrectly rendering with rel=undefined and target=undefined attributes. This fix ensures those attributes are only added when newTab is true. Fixes: #11752
This commit is contained in:
@@ -15,17 +15,13 @@ export const LinkHTMLConverter: HTMLConverter<any> = {
|
|||||||
submissionData,
|
submissionData,
|
||||||
})
|
})
|
||||||
|
|
||||||
const rel: string = node.fields.newTab ? ' rel="noopener noreferrer"' : ''
|
|
||||||
const target: string = node.fields.newTab ? ' target="_blank"' : ''
|
|
||||||
|
|
||||||
let href: string =
|
let href: string =
|
||||||
node.fields.linkType === 'custom' ? node.fields.url : node.fields.doc?.value?.id
|
node.fields.linkType === 'custom' ? node.fields.url : node.fields.doc?.value?.id
|
||||||
|
|
||||||
if (submissionData) {
|
if (submissionData) {
|
||||||
href = replaceDoubleCurlys(href, submissionData)
|
href = replaceDoubleCurlys(href, submissionData)
|
||||||
}
|
}
|
||||||
|
return `<a href="${href}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>${childrenText}</a>`
|
||||||
return `<a href="${href}"${target}${rel}>${childrenText}</a>`
|
|
||||||
},
|
},
|
||||||
nodeTypes: ['link'],
|
nodeTypes: ['link'],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,7 @@ export const LinkHTMLConverterAsync: (args: {
|
|||||||
})
|
})
|
||||||
).join('')
|
).join('')
|
||||||
|
|
||||||
const rel: string | undefined = node.fields.newTab ? 'noopener noreferrer' : undefined
|
return `<a${providedStyleTag} href="${node.fields.url}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>
|
||||||
const target: string | undefined = node.fields.newTab ? '_blank' : undefined
|
|
||||||
|
|
||||||
return `<a${providedStyleTag} href="${node.fields.url}" rel=${rel} target=${target}>
|
|
||||||
${children}
|
${children}
|
||||||
</a>`
|
</a>`
|
||||||
},
|
},
|
||||||
@@ -30,9 +27,6 @@ export const LinkHTMLConverterAsync: (args: {
|
|||||||
})
|
})
|
||||||
).join('')
|
).join('')
|
||||||
|
|
||||||
const rel: string | undefined = node.fields.newTab ? 'noopener noreferrer' : undefined
|
|
||||||
const target: string | undefined = node.fields.newTab ? '_blank' : undefined
|
|
||||||
|
|
||||||
let href: string = node.fields.url ?? ''
|
let href: string = node.fields.url ?? ''
|
||||||
if (node.fields.linkType === 'internal') {
|
if (node.fields.linkType === 'internal') {
|
||||||
if (internalDocToHref) {
|
if (internalDocToHref) {
|
||||||
@@ -45,7 +39,7 @@ export const LinkHTMLConverterAsync: (args: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return `<a${providedStyleTag} href="${href}" rel=${rel} target=${target}>
|
return `<a${providedStyleTag} href="${href}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>
|
||||||
${children}
|
${children}
|
||||||
</a>`
|
</a>`
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ export const LinkHTMLConverter: (args: {
|
|||||||
nodes: node.children,
|
nodes: node.children,
|
||||||
}).join('')
|
}).join('')
|
||||||
|
|
||||||
const rel: string | undefined = node.fields.newTab ? 'noopener noreferrer' : undefined
|
return `<a${providedStyleTag} href="${node.fields.url}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>
|
||||||
const target: string | undefined = node.fields.newTab ? '_blank' : undefined
|
|
||||||
|
|
||||||
return `<a${providedStyleTag} href="${node.fields.url}" rel=${rel} target=${target}>
|
|
||||||
${children}
|
${children}
|
||||||
</a>`
|
</a>`
|
||||||
},
|
},
|
||||||
@@ -21,9 +18,6 @@ export const LinkHTMLConverter: (args: {
|
|||||||
nodes: node.children,
|
nodes: node.children,
|
||||||
}).join('')
|
}).join('')
|
||||||
|
|
||||||
const rel: string | undefined = node.fields.newTab ? 'noopener noreferrer' : undefined
|
|
||||||
const target: string | undefined = node.fields.newTab ? '_blank' : undefined
|
|
||||||
|
|
||||||
let href: string = node.fields.url ?? ''
|
let href: string = node.fields.url ?? ''
|
||||||
if (node.fields.linkType === 'internal') {
|
if (node.fields.linkType === 'internal') {
|
||||||
if (internalDocToHref) {
|
if (internalDocToHref) {
|
||||||
@@ -36,7 +30,7 @@ export const LinkHTMLConverter: (args: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return `<a${providedStyleTag} href="${href}" rel=${rel} target=${target}>
|
return `<a${providedStyleTag} href="${href}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>
|
||||||
${children}
|
${children}
|
||||||
</a>`
|
</a>`
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -191,9 +191,6 @@ export const LinkFeature = createServerFeature<
|
|||||||
showHiddenFields,
|
showHiddenFields,
|
||||||
})
|
})
|
||||||
|
|
||||||
const rel: string = node.fields.newTab ? ' rel="noopener noreferrer"' : ''
|
|
||||||
const target: string = node.fields.newTab ? ' target="_blank"' : ''
|
|
||||||
|
|
||||||
let href: string = node.fields.url ?? ''
|
let href: string = node.fields.url ?? ''
|
||||||
if (node.fields.linkType === 'internal') {
|
if (node.fields.linkType === 'internal') {
|
||||||
href =
|
href =
|
||||||
@@ -202,7 +199,7 @@ export const LinkFeature = createServerFeature<
|
|||||||
: String(node.fields.doc?.value?.id)
|
: String(node.fields.doc?.value?.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
return `<a href="${href}"${target}${rel}>${childrenText}</a>`
|
return `<a href="${href}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>${childrenText}</a>`
|
||||||
},
|
},
|
||||||
nodeTypes: [AutoLinkNode.getType()],
|
nodeTypes: [AutoLinkNode.getType()],
|
||||||
},
|
},
|
||||||
@@ -240,15 +237,12 @@ export const LinkFeature = createServerFeature<
|
|||||||
showHiddenFields,
|
showHiddenFields,
|
||||||
})
|
})
|
||||||
|
|
||||||
const rel: string = node.fields.newTab ? ' rel="noopener noreferrer"' : ''
|
|
||||||
const target: string = node.fields.newTab ? ' target="_blank"' : ''
|
|
||||||
|
|
||||||
const href: string =
|
const href: string =
|
||||||
node.fields.linkType === 'custom'
|
node.fields.linkType === 'custom'
|
||||||
? escapeHTML(node.fields.url)
|
? escapeHTML(node.fields.url)
|
||||||
: (node.fields.doc?.value as string)
|
: (node.fields.doc?.value as string)
|
||||||
|
|
||||||
return `<a href="${href}"${target}${rel}>${childrenText}</a>`
|
return `<a href="${href}"${node.fields.newTab ? ' rel="noopener noreferrer" target="_blank"' : ''}>${childrenText}</a>`
|
||||||
},
|
},
|
||||||
nodeTypes: [LinkNode.getType()],
|
nodeTypes: [LinkNode.getType()],
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user