Fix type-check issues

This commit is contained in:
2025-05-18 16:36:20 +02:00
parent 3619cf4ed4
commit 60ab01b0c8
11 changed files with 41 additions and 38 deletions

View File

@@ -1,19 +1,20 @@
import { visit } from 'unist-util-visit';
import { lookupFileByName, getFileUrl } from '../api/git';
import { InlineContainerType, MARKDOWN_REGEX } from '../types/markdown';
import { Node } from 'unist';
import { Parent } from 'unist';
import { Text } from 'mdast';
import { lookupFileByName } from '@/api/file';
import { getFileUrl } from './fileHelpers';
/**
* Represents a wiki link match from the regex
*/
interface WikiLinkMatch {
fullMatch: string;
isImage: string;
isImage: boolean; // Changed from string to boolean
fileName: string;
displayText: string;
heading?: string;
heading?: string | undefined;
index: number;
}
@@ -171,11 +172,22 @@ export function remarkWikiLinks(workspaceName: string) {
const matches: WikiLinkMatch[] = [];
while ((match = regex.exec(node.value)) !== null) {
const [fullMatch, isImage, innerContent] = match;
// Provide default values during destructuring to handle potential undefined values
const [fullMatch = '', isImageMark = '', innerContent = ''] = match;
// Skip if we somehow got a match without the expected content
if (!innerContent) {
console.warn('Matched wiki link without inner content:', fullMatch);
continue;
}
let fileName: string;
let displayText: string;
let heading: string | undefined;
// Convert isImageMark string to boolean
const isImage: boolean = isImageMark === '!';
const pipeIndex: number = innerContent.indexOf('|');
const hashIndex: number = innerContent.indexOf('#');
@@ -231,7 +243,7 @@ export function remarkWikiLinks(workspaceName: string) {
lookupFileName
);
if (paths && paths.length > 0) {
if (paths && paths.length > 0 && paths[0]) {
const filePath: string = paths[0];
if (match.isImage) {
newNodes.push(