UNPKG

@analogjs/content

Version:

Content Rendering for Analog

161 lines (145 loc) 7.28 kB
import * as i0 from '@angular/core'; import { Provider, InjectionToken, AfterViewChecked, Signal, Type, AbstractType, ProviderToken } from '@angular/core'; import * as rxjs from 'rxjs'; import { Observable } from 'rxjs'; import * as mermaid from 'mermaid'; import { SafeHtml } from '@angular/platform-browser'; import * as marked from 'marked'; import { marked as marked$1 } from 'marked'; declare class AnchorNavigationDirective { private readonly document; private readonly location; private readonly router; handleNavigation(element: EventTarget | null): boolean; static ɵfac: i0.ɵɵFactoryDeclaration<AnchorNavigationDirective, never>; static ɵdir: i0.ɵɵDirectiveDeclaration<AnchorNavigationDirective, "[analogAnchorNavigation]", never, {}, {}, never, never, true, never>; } interface ContentFile<Attributes extends Record<string, any> = Record<string, any>> { filename: string; slug: string; content?: string | object; attributes: Attributes; } /** * Retrieves the static content using the provided param and/or prefix. * * @param param route parameter (default: 'slug') * @param fallback fallback text if content file is not found (default: 'No Content Found') */ declare function injectContent<Attributes extends Record<string, any> = Record<string, any>>(param?: string | { param: string; subdirectory: string; } | { customFilename: string; }, fallback?: string): Observable<ContentFile<Attributes | Record<string, never>>>; type TableOfContentItem = { id: string; level: number; text: string; }; declare abstract class ContentRenderer { render(content: string): Promise<string>; getContentHeadings(): Array<TableOfContentItem>; enhance(): void; static ɵfac: i0.ɵɵFactoryDeclaration<ContentRenderer, never>; static ɵprov: i0.ɵɵInjectableDeclaration<ContentRenderer>; } declare class NoopContentRenderer implements ContentRenderer { private readonly transferState; private contentId; /** * Generates a hash from the content string * to be used with the transfer state */ private generateHash; render(content: string): Promise<string>; enhance(): void; getContentHeadings(): Array<TableOfContentItem>; } declare function injectContentFiles<Attributes extends Record<string, any>>(filterFn?: InjectContentFilesFilterFunction<Attributes>): ContentFile<Attributes>[]; type InjectContentFilesFilterFunction<T extends Record<string, any>> = (value: ContentFile<T>, index: number, array: ContentFile<T>[]) => boolean; declare function injectContentFilesMap(): Record<string, () => Promise<string>>; declare class MarkdownContentRendererService implements ContentRenderer { #private; render(content: string): Promise<string>; /** * The method is meant to be called after `render()` */ getContentHeadings(): TableOfContentItem[]; enhance(): void; static ɵfac: i0.ɵɵFactoryDeclaration<MarkdownContentRendererService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<MarkdownContentRendererService>; } interface MarkdownRendererOptions { loadMermaid?: () => Promise<typeof mermaid>; } declare function withMarkdownRenderer(options?: MarkdownRendererOptions): Provider; declare function provideContent(...features: Provider[]): Provider[]; declare const MERMAID_IMPORT_TOKEN: InjectionToken<Promise<typeof mermaid>>; declare class AnalogMarkdownRouteComponent implements AfterViewChecked { private sanitizer; private route; contentRenderer: ContentRenderer; protected content: SafeHtml; classes: string; ngAfterViewChecked(): void; static ɵfac: i0.ɵɵFactoryDeclaration<AnalogMarkdownRouteComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<AnalogMarkdownRouteComponent, "analog-markdown-route", never, { "classes": { "alias": "classes"; "required": false; }; }, {}, never, never, true, [{ directive: typeof AnchorNavigationDirective; inputs: {}; outputs: {}; }]>; } declare class AnalogMarkdownComponent implements AfterViewChecked { private sanitizer; private route; private zone; private readonly platformId; private readonly mermaidImport; private mermaid; private contentSource; readonly htmlContent: Signal<SafeHtml | undefined>; readonly content: i0.InputSignal<string | object | null | undefined>; readonly classes: i0.InputSignal<string>; contentRenderer: ContentRenderer; constructor(); getContentSource(): rxjs.Observable<string | SafeHtml>; renderContent(content: string): Promise<string>; ngAfterViewChecked(): void; private loadMermaid; static ɵfac: i0.ɵɵFactoryDeclaration<AnalogMarkdownComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<AnalogMarkdownComponent, "analog-markdown", never, { "content": { "alias": "content"; "required": false; "isSignal": true; }; "classes": { "alias": "classes"; "required": false; "isSignal": true; }; }, {}, never, never, true, [{ directive: typeof AnchorNavigationDirective; inputs: {}; outputs: {}; }]>; } declare function parseRawContentFile<Attributes extends Record<string, any>>(rawContentFile: string): { content: string; attributes: Attributes; }; declare class MarkedSetupService { private readonly marked; private readonly highlighter; constructor(); getMarkedInstance(): typeof marked$1; static ɵfac: i0.ɵɵFactoryDeclaration<MarkedSetupService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<MarkedSetupService>; } interface MarkedContentHighlighter { augmentCodeBlock?(code: string, lang: string): string; } declare abstract class MarkedContentHighlighter { abstract getHighlightExtension(): marked.MarkedExtension; static ɵfac: i0.ɵɵFactoryDeclaration<MarkedContentHighlighter, never>; static ɵprov: i0.ɵɵInjectableDeclaration<MarkedContentHighlighter>; } declare function withHighlighter(provider: ({ useValue: MarkedContentHighlighter; } | { useClass: Type<MarkedContentHighlighter> | AbstractType<MarkedContentHighlighter>; } | { useFactory: (...deps: any[]) => MarkedContentHighlighter; }) & { deps?: ProviderToken<any>[]; }): Provider; type ContentListLoaderFunction<Attributes extends Record<string, any>> = () => Promise<ContentFile<Attributes>[]>; declare function injectContentListLoader<Attributes extends Record<string, any>>(): ContentListLoaderFunction<Attributes>; declare function withContentListLoader(): Provider; type ContentFileLoaderFunction = () => Promise<Record<string, () => Promise<string>>>; declare function injectContentFileLoader(): ContentFileLoaderFunction; declare function withContentFileLoader(): Provider; export { AnchorNavigationDirective, ContentRenderer, MERMAID_IMPORT_TOKEN, AnalogMarkdownComponent as MarkdownComponent, MarkdownContentRendererService, AnalogMarkdownRouteComponent as MarkdownRouteComponent, MarkedContentHighlighter, MarkedSetupService, NoopContentRenderer, injectContent, injectContentFileLoader, injectContentFiles, injectContentFilesMap, injectContentListLoader, parseRawContentFile, provideContent, withContentFileLoader, withContentListLoader, withHighlighter, withMarkdownRenderer }; export type { ContentFile, InjectContentFilesFilterFunction };