Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Highlighting in Tooltip #3152

Merged
merged 9 commits into from
Aug 28, 2023
Merged

Conversation

fabian-bizfactory
Copy link
Contributor

No description provided.

@fabian-bizfactory fabian-bizfactory self-assigned this Aug 16, 2023
@fabian-bizfactory fabian-bizfactory marked this pull request as ready for review August 16, 2023 15:14
@Kadrian
Copy link
Collaborator

Kadrian commented Aug 22, 2023

I like that you went for an own approach, tackling the Typescript compatibilities, without adding more libraries for highlighting.

But now the code is hard to read, contains a lot of type casts and edge case handling, uses Children methods (which is discouraged https://react.dev/reference/react/Children#alternatives ) and has to handle all those different components as part of react-markdown.

Could you maybe give this another try with the following idea:

  • create or find a remark plugin that traverses the markdown tree and wraps text matches into highlighted spans
  • use only span in components to match these highlighted spans and then render a <HighlightedText>

Copy link
Collaborator

@Kadrian Kadrian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

@fabian-bizfactory
Copy link
Contributor Author

I have just looked over the list of plugins again and found one that supports marks in Markdown ==.

I think that will be the easiest solution.

@@ -158,6 +159,11 @@ const ConceptLabel = ({
);
};

const mark = (text: string, words: string[]): string => {
const regex = new RegExp(words.join("|"), "gi");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess I would have used a useMemo to avoid calling new RegExp again and again when the infos change frequently on hovering around, while the words stay the same. But I quickly checked the performance impact and couldn't notice much. Hmm!

Copy link
Collaborator

@Kadrian Kadrian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a really great solution! Well done! :)

@fabian-bizfactory fabian-bizfactory merged commit a4b71b2 into develop Aug 28, 2023
6 checks passed
@delete-merged-branch delete-merged-branch bot deleted the fix/highlighting-in-tooltip branch August 28, 2023 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants