Skip to content
Open
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
18 changes: 18 additions & 0 deletions packages/angular-sdk-components/src/lib/_helpers/template-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ export class TemplateUtils {
// The raw metadata for `instructions` will be something like '@PARAGRAPH .SomeParagraphRule' but
// it is evaluated by core logic to the content
if (instructions !== 'casestep' && instructions !== 'none') {
// if the instructions contains a link, and the link is external, add a target attribute to open in a new window
if (instructions.includes('<a')) {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(instructions, 'text/html');
const anchorNode = htmlDoc.querySelector('a');
if (anchorNode) {
try {
const url = new URL(anchorNode.href);
if (url.origin !== window.location.origin) {
anchorNode.setAttribute('target', '_blank');
anchorNode.setAttribute('rel', 'noopener');
return htmlDoc.body.innerHTML;
}
} catch (e) {
console.error(e);
}
}
}
return instructions;
}
return undefined;
Expand Down