Skip to content

Commit e427107

Browse files
Merge pull request #763 from sudhanshutech/noti/markdown
changes to support markdown for notifications
2 parents d5104dd + fea30c1 commit e427107

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/custom/Markdown/index.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import ReactMarkdown from 'react-markdown';
22
import rehypeRaw from 'rehype-raw';
33
import remarkGfm from 'remark-gfm';
44
import {
5+
BasicAnchorMarkdown,
56
StyledMarkdown,
67
StyledMarkdownBlockquote,
78
StyledMarkdownH1,
@@ -97,3 +98,27 @@ export const RenderMarkdownTooltip: React.FC<RenderMarkdownProps> = ({ content }
9798
</ReactMarkdown>
9899
);
99100
};
101+
102+
// Markdown support for notifications markdown content
103+
export const BasicMarkdown: React.FC<RenderMarkdownProps> = ({ content }) => {
104+
return (
105+
<ReactMarkdown
106+
remarkPlugins={[remarkGfm]}
107+
components={{
108+
a: ({ ...props }) => (
109+
<BasicAnchorMarkdown
110+
onClick={(e) => {
111+
window.open(props.href, '_blank');
112+
e.stopPropagation();
113+
}}
114+
as="a"
115+
>
116+
{props.children}
117+
</BasicAnchorMarkdown>
118+
)
119+
}}
120+
>
121+
{content}
122+
</ReactMarkdown>
123+
);
124+
};

src/custom/Markdown/style.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ export const StyledMarkdown = styled('a')(({ theme }) => ({
1010
cursor: 'pointer'
1111
}));
1212

13+
// anchor style for notifications markdown content
14+
export const BasicAnchorMarkdown = styled('a')(() => ({
15+
textDecoration: 'none',
16+
'&:hover': {
17+
textDecoration: 'underline'
18+
},
19+
cursor: 'pointer'
20+
}));
21+
1322
export const StyledMarkdownP = styled('p')(({ theme }) => ({
1423
color: theme.palette.text.default,
1524
marginBlock: '0px',

src/custom/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { useWindowDimensions } from './Helpers/Dimension';
3131
import { useNotificationHandler } from './Helpers/Notification';
3232
import { ColView, updateVisibleColumns } from './Helpers/ResponsiveColumns/responsive-coulmns.tsx';
3333
import { LearningCard } from './LearningCard';
34-
import { RenderMarkdown } from './Markdown';
34+
import { BasicMarkdown, RenderMarkdown } from './Markdown';
3535
import { ModalCard } from './ModalCard';
3636
import PopperListener, { IPopperListener } from './PopperListener';
3737
import PromptComponent from './Prompt';
@@ -108,7 +108,7 @@ export {
108108

109109
// Markdown
110110
export { StyledMarkdown } from './Markdown/style';
111-
export { RenderMarkdown };
111+
export { BasicMarkdown, RenderMarkdown };
112112

113113
// Stepper
114114
export { CustomizedStepper, useStepper } from './Stepper';

0 commit comments

Comments
 (0)