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

Function Markdown

packages/shared/src/components/Markdown.tsx:61–219  ·  view source on GitHub ↗
({
  className,
  content,
  appendTooltipTo,
  openLinksInNewTab = false,
}: MarkdownProps)

Source from the content-addressed store, hash-verified

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

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
isImageElementFunction · 0.85
openMethod · 0.80

Tested by

no test coverage detected