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

Function Markdown

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

Source from the content-addressed store, hash-verified

107}
108
109export default function Markdown({
110 className,
111 content,
112 appendTooltipTo,
113}: MarkdownProps): ReactElement {
114 const purify = useDomPurify();
115 const { openModal } = useLazyModal();
116 const { isCompanion } = useRequestProtocol();
117 const containerRef = useRef<HTMLDivElement>(null);
118 const [userId, setUserId] = useState('');
119 const [offset, setOffset] = useState<CaretOffset>([0, 0]);
120 const [clearUser, cancelUserClearing] = useDebounceFn(
121 () => setUserId(''),
122 200,
123 );
124 const { data } = useQuery({
125 queryKey: generateQueryKey(RequestKey.UserShortById, { id: userId }),
126 queryFn: () => {
127 return getUserShortInfo(userId);
128 },
129 enabled: !!userId,
130 });
131
132 // Add accessibility attributes to images after render
133 useEffect(() => {
134 const container = containerRef.current;
135 if (!container) {
136 return;
137 }
138
139 const images = container.querySelectorAll('img[src]');
140 images.forEach((img) => {
141 img.setAttribute('tabindex', '0');
142 img.setAttribute('role', 'button');
143 img.setAttribute('aria-label', 'Open image');
144 });
145 });
146
147 const onHoverHandler: MouseEventHandler<HTMLDivElement> = useCallback(
148 (e) => {
149 const element = e.target;
150
151 if (!isMentionLink(element)) {
152 if (userId) {
153 clearUser();
154 }
155 return;
156 }
157
158 const { mentionId } = element.dataset;
159
160 if (!mentionId) {
161 return;
162 }
163
164 cancelUserClearing();
165 setOffset(getTooltipOffset(element));
166 setUserId(mentionId);

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected