@analogjs/content
Version:
Content Rendering for Analog
154 lines (140 loc) • 6.53 kB
TypeScript
import * as i0 from '@angular/core';
import { Provider, InjectionToken, AfterViewChecked, OnInit, OnChanges, ViewContainerRef, Type, AbstractType, ProviderToken } from '@angular/core';
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: HTMLElement): 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 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 OnInit, OnChanges, AfterViewChecked {
private sanitizer;
private route;
private zone;
private readonly platformId;
private readonly mermaidImport;
private mermaid;
content$: Observable<SafeHtml>;
content: string | object | undefined | null;
classes: string;
container: ViewContainerRef;
contentRenderer: ContentRenderer;
constructor();
ngOnInit(): void;
ngOnChanges(): void;
updateContent(): void;
getContentSource(): 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; }; "classes": { "alias": "classes"; "required": false; }; }, {}, 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;
export { AnchorNavigationDirective, ContentRenderer, MERMAID_IMPORT_TOKEN, AnalogMarkdownComponent as MarkdownComponent, MarkdownContentRendererService, AnalogMarkdownRouteComponent as MarkdownRouteComponent, MarkedContentHighlighter, MarkedSetupService, NoopContentRenderer, injectContent, injectContentFiles, parseRawContentFile, provideContent, withHighlighter, withMarkdownRenderer };
export type { ContentFile };