mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 02:05:21 -04:00
Open links always in new tabs (#912)
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
parent
184a972c26
commit
528e67e11e
3 changed files with 32 additions and 4 deletions
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { DomElement } from 'domhandler'
|
||||
import { ReactElement } from 'react'
|
||||
import { ComponentReplacer, SubNodeTransform } from '../ComponentReplacer'
|
||||
|
||||
export class LinkInNewTabReplacer extends ComponentReplacer {
|
||||
public getReplacement (node: DomElement, subNodeTransform: SubNodeTransform): (ReactElement | null | undefined) {
|
||||
const isJumpMark = node.attribs?.href?.substr(0, 1) === '#'
|
||||
|
||||
if (node.name !== 'a' || isJumpMark) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return <a {...node.attribs} rel='noopener noreferrer' target='_blank'>
|
||||
{
|
||||
node.children?.map((child, index) => subNodeTransform(child, index))
|
||||
}
|
||||
</a>
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue