-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: highlight links in cards and pqir and tooltips (#746)
- Loading branch information
Showing
5 changed files
with
58 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Typography, TypographyProps } from "@equinor/eds-core-react"; | ||
import styles from "../Node.module.scss"; | ||
|
||
export function FormatNodeText({ | ||
children, | ||
...typographyProps | ||
}: TypographyProps) { | ||
if (!children) return null; | ||
const text = children.toString(); | ||
// Pattern matching for Markdown hyperlink urls | ||
const pattern = /\[([^\]]+)]\(([^)]+)\)/g; | ||
const result = []; | ||
let lastIndex = 0; | ||
|
||
text.replace(pattern, (match, linkText, _, offset) => { | ||
if (lastIndex <= offset) { | ||
result.push(<>{text.slice(lastIndex, offset)}</>); | ||
} | ||
|
||
result.push( | ||
<Typography | ||
className={styles[typographyProps.className ?? ""]} | ||
style={{ cursor: "grab" }} | ||
link | ||
> | ||
{linkText} | ||
</Typography> | ||
); | ||
lastIndex = offset + match.length; | ||
return linkText; | ||
}); | ||
|
||
if (lastIndex < text.length) { | ||
result.push(<>{text.slice(lastIndex)}</>); | ||
} | ||
|
||
return <Typography {...typographyProps}>{result}</Typography>; | ||
} |
This file was deleted.
Oops, something went wrong.