MCPcopy Create free account
hub / github.com/callumalpass/tasknotes / parseWikilinkSync

Function parseWikilinkSync

src/editor/TaskLinkOverlay.ts:443–505  ·  view source on GitHub ↗
(
	wikilinkText: string
)

Source from the content-addressed store, hash-verified

441
442// Synchronous helper functions for State Field context
443function parseWikilinkSync(
444 wikilinkText: string
445): ParsedTaskLink | null {
446 // Validate input
447 if (!wikilinkText || typeof wikilinkText !== "string") {
448 return null;
449 }
450
451 // Validate wikilink format
452 if (wikilinkText.length < 4 || !wikilinkText.startsWith("[[") || !wikilinkText.endsWith("]]")) {
453 return null;
454 }
455
456 const content = wikilinkText.slice(2, -2).trim();
457 if (!content || content.length === 0) {
458 return null;
459 }
460
461 // Prevent processing of extremely long links
462 if (content.length > 500) {
463 return null;
464 }
465
466 // First check for alias syntax: [[path|alias]]
467 const pipeIndex = content.indexOf("|");
468 if (pipeIndex !== -1) {
469 const pathPart = content.slice(0, pipeIndex).trim();
470 const aliasPart = content.slice(pipeIndex + 1).trim();
471
472 if (!pathPart || !aliasPart) {
473 return null;
474 }
475
476 // Parse the path part for subpaths/headings
477 const parsed = parseLinktext(pathPart);
478
479 // Validate the path
480 if (!parsed.path) {
481 return null;
482 }
483
484 return {
485 linkPath: parsed.path,
486 displayText: aliasPart,
487 subpath: parsed.subpath || undefined,
488 hasExplicitAlias: true,
489 };
490 }
491
492 // No alias, use parseLinktext for path and subpath
493 const parsed = parseLinktext(content);
494
495 // Validate the path
496 if (!parsed.path) {
497 return null;
498 }
499
500 return {

Callers 1

buildTaskLinkDecorationsFunction · 0.85

Calls 1

parseLinktextFunction · 0.90

Tested by

no test coverage detected