Bugfix/links in docs (#2561)

* chore: fix markdown component

* Refactor MarkDown component to remove unnecessary useCallback hooks
This commit is contained in:
Sanjai Kumar 2024-07-04 11:38:35 +05:30 committed by GitHub
parent 0d204694a6
commit 01605f6f2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,15 +1,28 @@
import MarkdownIt from 'markdown-it';
import StyledWrapper from './StyledWrapper';
import * as React from 'react';
import React from 'react';
const md = new MarkdownIt();
const Markdown = ({ onDoubleClick, content }) => {
const handleOnClick = (event) => {
const target = event.target;
if (target.tagName === 'A') {
event.preventDefault();
const href = target.getAttribute('href');
if (href) {
window.open(href, '_blank');
return;
}
}
};
const handleOnDoubleClick = (event) => {
if (event?.detail === 2) {
if (event.detail === 2) {
onDoubleClick();
}
};
const htmlFromMarkdown = md.render(content || '');
return (
@ -17,7 +30,8 @@ const Markdown = ({ onDoubleClick, content }) => {
<div
className="markdown-body"
dangerouslySetInnerHTML={{ __html: htmlFromMarkdown }}
onClick={handleOnDoubleClick}
onClick={handleOnClick}
onDoubleClick={handleOnDoubleClick}
/>
</StyledWrapper>
);