diff --git a/src/components/markdown/markdown.module.css b/src/components/markdown/markdown.module.css index b894ce63..8c12a714 100644 --- a/src/components/markdown/markdown.module.css +++ b/src/components/markdown/markdown.module.css @@ -19,3 +19,13 @@ .hrWrapper hr { margin: 0; } + +.embedButton { + color: var(--button-desktop-text-color); + text-transform: capitalize; +} + +.embedButton:hover { + cursor: pointer; + color: var(--button-desktop-text-color-hover); +} \ No newline at end of file diff --git a/src/components/markdown/markdown.tsx b/src/components/markdown/markdown.tsx index ec4ef6ec..31542885 100644 --- a/src/components/markdown/markdown.tsx +++ b/src/components/markdown/markdown.tsx @@ -1,9 +1,12 @@ -import React, { useMemo } from 'react'; -import styles from './markdown.module.css'; +import React, { useMemo, useState } from 'react'; import ReactMarkdown from 'react-markdown'; -import rehypeSanitize, { defaultSchema } from 'rehype-sanitize'; import remarkGfm from 'remark-gfm'; import supersub from 'remark-supersub'; +import rehypeSanitize, { defaultSchema } from 'rehype-sanitize'; +import styles from './markdown.module.css'; +import { useTranslation } from 'react-i18next'; +import { getLinkMediaInfo, getHasThumbnail } from '../../lib/utils/media-utils'; +import CommentMedia from '../comment-media'; interface MarkdownProps { content: string; @@ -55,6 +58,9 @@ const Markdown = ({ content }: MarkdownProps) => { remarkPlugins.push([blockquoteToGreentext]); + const { t } = useTranslation(); + const [showMedia, setShowMedia] = useState(false); + return ( {
), + a: ({ href, children }) => { + if (href) { + const linkMediaInfo = getLinkMediaInfo(href); + if (getHasThumbnail(linkMediaInfo, href)) { + return ( + <> + + {children} + {' '} + [ + setShowMedia(!showMedia)}> + {showMedia ? t('remove') : t('embed')} + + ] + {showMedia && ( + <> +
+ + + )} + + ); + } else { + return ( + + {children} + + ); + } + } + }, }} />