diff --git a/source/config.ts b/source/config.ts index 4c7ec68..9628721 100644 --- a/source/config.ts +++ b/source/config.ts @@ -1,6 +1,5 @@ import {mkdirSync, readFileSync, writeFileSync, existsSync} from 'node:fs'; import {join} from 'node:path'; -// @ts-expect-error no type declarations import xdg from '@folder/xdg'; export type Config = { diff --git a/source/task-list-view.tsx b/source/task-list-view.tsx index 8702d44..ef3a0d8 100644 --- a/source/task-list-view.tsx +++ b/source/task-list-view.tsx @@ -1,13 +1,31 @@ import React from 'react'; import {Text} from 'ink'; +import Link from 'ink-link'; import {type Task} from '@doist/todoist-api-typescript'; -import {priorityColor} from './utils.js'; +import {parseMdLink, priorityColor} from './utils.js'; type TaskListViewProps = { tasks: Task[]; projects: Map; }; +function Content({text}: {text: string}) { + const segments = parseMdLink(text); + return ( + <> + {segments.map((seg, i) => + seg.type === 'link' ? ( + + {seg.text} + + ) : ( + {seg.text} + ), + )} + + ); +} + function ProjectLabel({name}: {name: string | undefined}) { if (!name) return null; return ( @@ -55,7 +73,7 @@ export default function TaskListView({tasks, projects}: TaskListViewProps) { {tasks.length === 0 && No tasks} {tasks.map((task, i) => ( - {i + 1}. {task.content} + {i + 1}. diff --git a/source/utils.ts b/source/utils.ts index afdd9cc..ace5999 100644 --- a/source/utils.ts +++ b/source/utils.ts @@ -10,3 +10,31 @@ export function priorityColor(displayPriority: number): string | undefined { return undefined; } } + +export type ContentSegment = + | {type: 'text'; text: string} + | {type: 'link'; text: string; url: string}; + +export function parseMdLink(content: string): ContentSegment[] { + const segments: ContentSegment[] = []; + const linkPattern = /\[([^\]]+)\]\(([^)]+)\)/g; + + let lastIndex = 0; + let match; + + while ((match = linkPattern.exec(content)) !== null) { + if (match.index > lastIndex) { + segments.push({type: 'text', text: content.slice(lastIndex, match.index)}); + } + + segments.push({type: 'link', text: match[1]!, url: match[2]!}); + lastIndex = match.index + match[0].length; + } + + if (lastIndex < content.length) { + segments.push({type: 'text', text: content.slice(lastIndex)}); + } + + return segments; +} +