types#AnnotationList TypeScript Examples

The following examples show how to use types#AnnotationList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: annotationFileUtils.tsx    From obsidian-annotator with GNU Affero General Public License v3.0 6 votes vote down vote up
export async function loadAnnotations(
    url: URL | null,
    vault: Vault,
    annotationFilePath: string
): Promise<AnnotationList> {
    const tfile = vault.getAbstractFileByPath(annotationFilePath);
    if (tfile instanceof TFile) {
        const text = await vault.read(tfile);
        return loadAnnotationsAtUriFromFileText(url, text);
    } else {
        return loadAnnotationsAtUriFromFileText(url, null);
    }
}
Example #2
Source File: annotationUtils.tsx    From obsidian-annotator with GNU Affero General Public License v3.0 6 votes vote down vote up
export function loadAnnotationsAtUriFromFileText(url: URL | null, fileText: string | null): AnnotationList {
    const params = url ? Object.fromEntries(url.searchParams.entries()) : null;
    if (params?.uri == 'app://obsidian.md/index.html') {
        return { rows: [], total: 0 };
    }

    const rows = [];

    const annotationRegex = makeAnnotationBlockRegex();
    if (fileText !== null) {
        let m: RegExpExecArray;
        while ((m = annotationRegex.exec(fileText)) !== null) {
            if (m.index === annotationRegex.lastIndex) {
                annotationRegex.lastIndex++;
            }
            const {
                groups: { annotationBlock, annotationId }
            } = m;
            const completeAnnotation = getAnnotationFromAnnotationBlock(annotationBlock, annotationId);
            const annotationDocumentIdentifiers = [
                completeAnnotation.document?.documentFingerprint,
                completeAnnotation.uri
            ];

            //The check against SAMPLE_PDF_URL is for backwards compability.
            if (
                url === null ||
                annotationDocumentIdentifiers.includes(params.uri) ||
                annotationDocumentIdentifiers.includes(encodeURI(params.uri)) ||
                annotationDocumentIdentifiers.includes(decodeURI(params.uri)) ||
                annotationDocumentIdentifiers.includes(SAMPLE_PDF_URL)
            ) {
                rows.push(completeAnnotation);
            }
        }
    }
    return { rows, total: rows.length };
}