MCPcopy Create free account
hub / github.com/dailydotdev/apps / Markdown

Function Markdown

packages/shared/src/components/Markdown.tsx:60–200  ·  view source on GitHub ↗
({
  className,
  content,
  appendTooltipTo,
}: MarkdownProps)

Source from the content-addressed store, hash-verified

58}
59
60export default function Markdown({
61 className,
62 content,
63 appendTooltipTo,
64}: MarkdownProps): ReactElement {
65 const purify = useDomPurify();
66 const { openModal } = useLazyModal();
67 const { isCompanion } = useRequestProtocol();
68 const containerRef = useRef<HTMLDivElement>(null);
69 const [userId, setUserId] = useState('');
70 const [offset, setOffset] = useState<CaretOffset>([0, 0]);
71 const [clearUser, cancelUserClearing] = useDebounceFn(
72 () => setUserId(''),
73 200,
74 );
75 const { data } = useQuery({
76 queryKey: generateQueryKey(RequestKey.UserShortById, { id: userId }),
77 queryFn: () => {
78 return getUserShortInfo(userId);
79 },
80 enabled: !!userId,
81 });
82
83 // Add accessibility attributes to images after render
84 useEffect(() => {
85 const container = containerRef.current;
86 if (!container) {
87 return;
88 }
89
90 const images = container.querySelectorAll('img[src]');
91 images.forEach((img) => {
92 img.setAttribute('tabindex', '0');
93 img.setAttribute('role', 'button');
94 img.setAttribute('aria-label', 'Open image');
95 });
96 });
97
98 const onHoverHandler: MouseEventHandler<HTMLDivElement> = useCallback(
99 (e) => {
100 const element = e.target;
101
102 if (!isMentionLink(element)) {
103 if (userId) {
104 clearUser();
105 }
106 return;
107 }
108
109 const { mentionId } = element.dataset;
110
111 if (!mentionId) {
112 return;
113 }
114
115 cancelUserClearing();
116 setOffset(getTooltipOffset(element));
117 setUserId(mentionId);

Callers

nothing calls this directly

Calls 11

useDomPurifyFunction · 0.90
useLazyModalFunction · 0.90
useRequestProtocolFunction · 0.90
generateQueryKeyFunction · 0.90
getUserShortInfoFunction · 0.90
getImageOriginRectFunction · 0.90
useDebounceFnFunction · 0.85
isMentionLinkFunction · 0.85
getTooltipOffsetFunction · 0.85
openModalFunction · 0.85
isImageElementFunction · 0.85

Tested by

no test coverage detected