MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / onContentClick

Function onContentClick

src/pages/markdownPreview/index.js:302–349  ·  view source on GitHub ↗
(event)

Source from the content-addressed store, hash-verified

300 initHighlighting();
301
302 async function onContentClick(event) {
303 const link = event.target.closest("a[href]");
304 if (!link) return;
305
306 const originalHref = link.getAttribute("href") || "";
307 const resolvedHref =
308 link.getAttribute("data-resolved-href") ||
309 resolveMarkdownTarget(
310 originalHref,
311 getMarkdownBaseUri(previewState.file),
312 );
313 event.preventDefault();
314 event.stopPropagation();
315
316 if (originalHref.startsWith("#")) {
317 scrollToHash(originalHref.slice(1));
318 return;
319 }
320
321 if (isExternalLink(originalHref)) {
322 system.openInBrowser(originalHref);
323 return;
324 }
325
326 const hashIndex = resolvedHref.indexOf("#");
327 const targetPath =
328 hashIndex === -1 ? resolvedHref : resolvedHref.slice(0, hashIndex);
329 const targetHash =
330 hashIndex === -1 ? "" : resolvedHref.slice(hashIndex + 1);
331
332 if (!targetPath && targetHash) {
333 scrollToHash(targetHash);
334 return;
335 }
336
337 if (isMarkdownPath(resolvedHref)) {
338 await openFile(targetPath, { render: true });
339 const nextFile =
340 editorManager.getFile(targetPath, "uri") || editorManager.activeFile;
341 if (nextFile) {
342 await bind(nextFile, targetHash);
343 }
344 return;
345 }
346
347 $page.hide();
348 await openFile(targetPath, { render: true });
349 }
350
351 function scrollToHash(targetId) {
352 const target = getTargetElement(previewState.content, targetId);

Callers

nothing calls this directly

Calls 11

resolveMarkdownTargetFunction · 0.90
getMarkdownBaseUriFunction · 0.90
isExternalLinkFunction · 0.90
isMarkdownPathFunction · 0.90
scrollToHashFunction · 0.85
bindFunction · 0.85
openInBrowserMethod · 0.65
getFileMethod · 0.65
preventDefaultMethod · 0.45
stopPropagationMethod · 0.45
hideMethod · 0.45

Tested by

no test coverage detected