Skip to content

Commit

Permalink
Made SR-text for links optional and added checks if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnp committed Oct 3, 2022
1 parent 9640d74 commit aba5dce
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ interface Resources {
adresseKomponent_velgTjeneste?: string;
adresseKomponent_feilmelding?: string;
adresseKomponent_loadError?: string;
linkOpensInNewTab?: string;
}
```
Expand Down
6 changes: 3 additions & 3 deletions src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ DOMPurify.setConfig({ ADD_ATTR: ['target'] });
const renderer = new marked.Renderer();
let resources: Resources;
renderer.link = (href: string, title: string, text: string): string => {
return `<a href=${href} ${title ? `title=${title}` : ''} target="_blank" aria-label=${
resources.linkOpensInNewTab
return `<a href=${href} ${title ? `title=${title}` : ''} target="_blank" ${
resources.linkOpensInNewTab ? `aria-label=${resources.linkOpensInNewTab}` : ''
} class="external">${text}</a>`;
};
const rendererSameWindow = new marked.Renderer();
rendererSameWindow.link = (href: string, title: string, text: string): string => {
return `<a href=${href} ${title ? `title=${title}` : ''} target="${openNewIfAbsolute(href)}" ${
openNewIfAbsolute(href) === '_blank' ? `aria-label=${resources.linkOpensInNewTab}` : ''
openNewIfAbsolute(href) === '_blank' && resources.linkOpensInNewTab ? `aria-label=${resources.linkOpensInNewTab}` : ''
}>${text}</a>`;
};

Expand Down
2 changes: 1 addition & 1 deletion src/util/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,5 +386,5 @@ export interface Resources {
/**
* Åpnes i ny fane
*/
linkOpensInNewTab: string;
linkOpensInNewTab?: string;
}

0 comments on commit aba5dce

Please sign in to comment.