import * as i0 from '@angular/core'; import { InjectionToken, Provider, Injector, Type, OnInit, AfterViewInit, OnDestroy, EnvironmentProviders } from '@angular/core'; import * as marked from 'marked'; import { MarkedOptions, TokensList, Renderer, Tokenizer } from 'marked'; import * as i1 from '@angular/router'; /** * Global configuration of NgeMarkdownModule */ declare type NgeMarkdownConfig = MarkedOptions & { /** * Class name (or names) indicating that the page is currently in dark mode. * Pass an array to match any of several dark classes across a multi-page app. */ darkThemeClassName?: string | string[]; }; /** * Theme configuration of NgeMarkdownModule */ interface NgeMarkdownTheme { /** * Name of the theme (the @Input() theme property of NgeMarkdownComponent) */ name: string; /** * Style URL for the theme */ styleUrl: string; } declare const NGE_MARKDOWN_CONFIG: InjectionToken; declare const NGE_MARKDOWN_THEMES: InjectionToken; /** @deprecated Use `provideNgeMarkdown(withConfig(...))` instead; will be removed in the next major. */ declare const NgeMarkdownConfigProvider: (config: NgeMarkdownConfig | (() => NgeMarkdownConfig)) => Provider; /** @deprecated Use `provideNgeMarkdown(withThemes(...))` instead; will be removed in the next major. */ declare const NgeMarkdownThemeProvider: (...themes: NgeMarkdownTheme[]) => Provider[]; declare type AstTransformer = (tokens: TokensList) => TokensList; declare type HtmlTransformer = (element: HTMLElement) => void | Promise; declare type MarkdownTransformer = (markdown: string) => string; declare type RendererTransformer = (renderer: Renderer) => Renderer; declare type TokenizerTransformer = (tokenizer: Tokenizer) => Tokenizer; /** * Nge markdown transformer used by the contributions. */ declare class NgeMarkdownTransformer { /** Configuration option */ readonly config: NgeMarkdownConfig; private readonly astTransformers; private readonly htmlTransformers; private readonly markdownTransformers; private readonly rendererTransformers; private readonly tokenizerTransformers; constructor( /** Configuration option */ config: NgeMarkdownConfig); /** * Registers a function to call to update the ast generated by the markdown compiler. * @param transform the function to call. */ addAstTransformer(transform: AstTransformer): void; /** * Registers a function to call to transform the html generated by the markdown compiler. * @param transformer the function to call. */ addHtmlTransformer(transformer: HtmlTransformer): void; /** * Registers a function to call to transform the markdown before it's parsed by the markdown compiler. * @param transform the function to call. */ addMarkdownTransformer(transform: MarkdownTransformer): void; /** * Registers a function to call to update marked library renderer. * @param transform the function to call. */ addRendererTransformer(transform: RendererTransformer): void; /** * Registers a function to call to update marked library tokenizer. * @param transform the function to call. */ addTokenizerTransformer(transform: TokenizerTransformer): void; /** * Apply the registered ast transformer functions to the given ast. * @param ast the ast to transform. * @returns the transformed ast. */ transformAst(ast: TokensList): TokensList; /** * Apply the registered html transformer functions to the given html. * @param element the html element to transform. * @returns the transformed html. */ transformHTML(element: HTMLElement): Promise; /** * Apply the registered markdown transformer functions to the given markdown. * @param markdown the markdown to transform. * @returns the transformed markdown. */ transformMarkdown(markdown: string): string; /** * Apply the registered renderer transformer functions to the given renderer. * @param renderer the renderer to transform. * @returns the transformed renderer. */ transformRenderer(renderer: Renderer): Renderer; /** * Apply the registered tokenizer transformer functions to the given tokenizer. * @param tokenizer the tokenizer to transform. * @returns the transformed tokenizer. */ transformTokenizer(tokenizer: Tokenizer): Tokenizer; /** * Add new stylesheet element to the document. * @param url url to the stylesheet. * @returns A promise that resolves once the element is loaded. */ addStyle(url: string): Promise; /** * Add new script element to the document. * @param url url to the script. * @returns A promise that resolves once the element is loaded. */ addScript(url: string): Promise; } /** * Implements this interface to contribute to nge-markdown. */ interface NgeMarkdownContribution { /** * List of scripts and styles dependencies to loads * before calling the `transform` methods. * * The dependencies are to be loaded only once. */ dependencies?(): ['style' | 'script', string][]; /** * Contributes to nge-markdown api. * @param api nge-markdown api. */ contribute(api: NgeMarkdownTransformer): void; } /** Inject this token to get the list of contributions to nge-markdown api. */ declare const NGE_MARKDOWN_CONTRIBUTION: InjectionToken; /** * Contribution to add collapsible styled block to markdown syntax. */ declare class NgeMarkdownAdmonitions implements NgeMarkdownContribution { private readonly document; contribute(transformer: NgeMarkdownTransformer): void; private addStyles; private createAdmonitions; private autoFixAdmonitionsSyntax; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Injection token to register `NgeMarkdownAdmonitions` contribution. * * @deprecated Use `provideNgeMarkdown(withAdmonitions())` instead; will be removed in the next major. */ declare const NgeMarkdownAdmonitionsProvider: Provider; /** Options to pass to `NgeMarkdownEmoji` contribution. */ interface NgeMarkdownEmojiOptions { /** URL to load joypixels script (default https://cdn.jsdelivr.net/npm/emoji-toolkit@6.0.1/lib/js/joypixels.min.js). */ url: string; } /** Injection token to pass custom options to `NgeMarkdownEmoji` contribution. */ declare const NGE_MARKDOWN_EMOJI_OPTIONS: InjectionToken; /** * Contribution to use emoji in markdown using [emoji-toolkit](https://github.com/joypixels/emoji-toolkit) library. */ declare class NgeMarkdownEmoji implements NgeMarkdownContribution { private readonly options; dependencies(): any[]; contribute(transformer: NgeMarkdownTransformer): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Provider to register `NgeMarkdownEmoji` contribution. * * @deprecated Use `provideNgeMarkdown(withEmoji())` instead; will be removed in the next major. */ declare const NgeMarkdownEmojiProvider: Provider; /** * Provider to pass options to `NgeMarkdownEmoji` contribution. * @param options `NgeMarkdownEmoji` options. * * @deprecated Use `provideNgeMarkdown(withEmoji(options))` instead; will be removed in the next major. */ declare function NgeMarkdownEmojiOptionsProvider(options: NgeMarkdownEmojiOptions): Provider; /** An extra toolbar action for a code block. */ interface CodeAction { /** Accessible title and tooltip. */ title: string; /** Inline SVG markup for the icon. */ icon: string; /** Invoked with the raw code when the button is clicked. */ run: (code: string) => void; } /** Fence flag exposed on the rendered `pre`, e.g. from ```ts stackblitz. */ declare const DATA_STACKBLITZ = "data-nge-md-hl-stackblitz"; /** Context handed to a code-action provider for one highlighted block. */ interface NgeMarkdownCodeActionContext { /** The rendered `pre` element, carrying the fence flags as data attributes. */ pre: HTMLElement; /** The raw code, captured before colorizing mutates the DOM. */ code: string; /** Fence language. */ language: string; /** Fence filename, if any. */ filename?: string; } /** * Contributes a toolbar action to a highlighted code block, or `null` to skip * it. Register with `multi: true` on {@link NGE_MARKDOWN_CODE_ACTIONS}. Keeping * actions behind this token lets optional integrations (StackBlitz, ...) stay * out of the highlighter's module graph until their feature is opted into. */ type NgeMarkdownCodeActionProvider = (context: NgeMarkdownCodeActionContext) => CodeAction | null; /** Multi-provider token for code-block toolbar actions. */ declare const NGE_MARKDOWN_CODE_ACTIONS: InjectionToken; /** * Highlight options. */ interface NgeMarkdownHighlightOptions { /** <code></code> element to colorize. */ element: HTMLElement; /** Target language (default plaintext) */ language?: string; /** * Start line number or a space separated list of line numbers to show. * * Example: * * *Show all line numbers starting 1* * * `"1"` * * *Show all line numbers from 1 to 4* * * `"1-4"` * * *Show lines 2 4 5 6 7 9* * * `"2 4-7 9"` * */ lines?: string; /** * A space separated list of line numbers to highlight. * * Example: * * *Highlight line 1* * * `"1"` * * *Highlight all lines from 1 to 4* * * `"1-4"` * * *Highlightw lines 2 4 5 6 7 9* * * `"2 4-7 9"` */ highlights?: string; /** Filename to display */ filename?: string; } /** * Highlighter service representation. */ interface NgeMarkdownHighlighterService { /** * Whether the service also works during server rendering. Browser-bound * services (monaco) leave it unset: their blocks render plain on the server * and colorize on the client. A server-capable service (shiki) sets it to * true so prerendered pages ship highlighted HTML. */ ssr?: boolean; /** * Function called to hightlight an HTMLElement code. * @param injector Injector reference to use Angular dependency injection. * @param options Highlight options. */ highligtht?(injector: Injector, options: NgeMarkdownHighlightOptions): void | Promise; } /** * Injection token to register a highlighter service. */ declare const NGE_MARKDOWN_HIGHLIGHTER_SERVICE: InjectionToken; /** * Contribution to add an abstract syntax highlighter. */ declare class NgeMarkdownHighlighter implements NgeMarkdownContribution { private readonly injector; private readonly options; contribute(transformer: NgeMarkdownTransformer): void; private createAttributes; private colorizeCodes; private escapeHtml; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Injection token to register `NgeMarkdownHighlighter` contribution. * * @deprecated Use `provideNgeMarkdown(withHighlighter())` instead; will be removed in the next major. */ declare const NgeMarkdownHighlighterProvider: Provider; /** * Highlighter service backed by a Monaco colorizer (`NgeMonacoColorizerService`), * resolved lazily through the injector so markdown never imports monaco. */ declare function monacoHighlighterService(type: Type): NgeMarkdownHighlighterService; /** * Provider to register `NgeMonacoColorizerService` as the syntax highlighter. * @param type A reference to NgeMonacoColorizerService type. * @deprecated Use `provideNgeMarkdown(withHighlighter(NgeMonacoColorizerService))` instead; will be removed in the next major. */ declare function NgeMarkdownHighlighterMonacoProvider(type: Type): { provide: InjectionToken; useValue: NgeMarkdownHighlighterService; }; /** * Contribution to use icons in markdown library using https://icongr.am/. */ declare class NgeMarkdownIcons implements NgeMarkdownContribution { contribute(transformer: NgeMarkdownTransformer): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Injection token to register `NgeMarkdownIcons` contribution. * * @deprecated Use `provideNgeMarkdown(withIcons())` instead; will be removed in the next major. */ declare const NgeMarkdownIconsProvider: Provider; /** Custom options to pass to NgeMarkdownKatex contribution. */ interface NgeMarkdownKatexOptions { /** Base url to load katex scripts and styles. (default https://cdn.jsdelivr.net/npm/katex@0.15.1/dist) */ baseUrl?: string; /** Options to pass to katex render function. https://katex.org/docs/options.html */ options?: Record; /** Katex extensions to include. https://katex.org/docs/libs.html */ extensions?: { /** https://github.com/Khan/KaTeX/tree/master/contrib/mhchem (default to `true`) */ mhchem?: boolean; /** https://github.com/Khan/KaTeX/tree/master/contrib/copy-tex (default to `true`) */ copyTex?: boolean; }; } /** Custom options to pass to NgeMarkdownKatex contribution. */ declare const NGE_MARKDOWN_KATEX_OPTIONS: InjectionToken; /** * Contribution to render math expressions in markdown using [Katex](https://katex.org) library. */ declare class NgeMarkdownKatex implements NgeMarkdownContribution { private readonly options; constructor(); dependencies(): any; contribute(transformer: NgeMarkdownTransformer): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Provider to render math expressions in markdown using [Katex](https://katex.org) library. * * @deprecated Use `provideNgeMarkdown(withKatex())` instead; will be removed in the next major. */ declare const NgeMarkdownKatexProvider: Provider; /** * Provider to pass options to `NgeMarkdownKatex` contribution. * @param options `NgeMarkdownKatex` options. * * @deprecated Use `provideNgeMarkdown(withKatex(options))` instead; will be removed in the next major. */ declare function NgeMarkdownKatexOptionsProvider(options: NgeMarkdownKatexOptions): Provider; /** * Contribution to handle fragment navigation in anchor elements. */ declare class NgeMarkdownLinkAnchor implements NgeMarkdownContribution { private readonly router; private readonly location; contribute(transformer: NgeMarkdownTransformer): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Injection token to register `NgeMarkdownLinkAnchor` contribution. * * @deprecated Use `provideNgeMarkdown(withLinkAnchor())` instead; will be removed in the next major. */ declare const NgeMarkdownLinkAnchorProvider: Provider; /** * Contribution to render tabs inside markdown files. */ declare class NgeMarkdownTabbedSet implements NgeMarkdownContribution { private readonly document; contribute(transformer: NgeMarkdownTransformer): void; private createTabs; private addStyles; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Injection token to register `NgeMarkdownTabbedSet` contribution. * * @deprecated Use `provideNgeMarkdown(withTabbedSet())` instead; will be removed in the next major. */ declare const NgeMarkdownTabbedSetProvider: Provider; /** Loads the component mounted for a keyword. */ type NgeMarkdownComponentLoader = () => Type | Promise | { default: Type; }>; /** Map of a custom tag name to the component it mounts. */ type NgeMarkdownComponents = Record; /** * Registry of components embedded in Markdown by keyword. * * A registered keyword written as a tag (``) is replaced by its * component once the Markdown is rendered. Only registered keywords are mounted; every other tag * stays plain HTML, so the feature is opt-in and never collides with real markup. */ declare const NGE_MARKDOWN_COMPONENTS: InjectionToken; /** * Register components that can be embedded in Markdown by keyword. * * ```ts * NgeMarkdownComponentsProvider({ * 'color-picker': () => import('./color-picker.component').then((m) => m.ColorPickerComponent), * }) * ``` * * Then in Markdown, write the keyword as a tag: ``. Tag attributes are * passed to the component as inputs, so `` sets `theme`. * Prefer hyphenated keywords so they are valid custom-element names. * * @deprecated Use `provideNgeMarkdown(withComponents(...))` instead; will be removed in the next major. */ declare const NgeMarkdownComponentsProvider: (components: NgeMarkdownComponents) => Provider; declare class NgeMarkdownComponent implements OnInit, AfterViewInit, OnDestroy { private readonly el; private readonly document; private readonly http; private readonly markdownService; private readonly pendingTasks; private readonly resourceLoader; private readonly changeDetectorRef; private readonly appRef; private readonly environmentInjector; private readonly components; private readonly themes; private readonly contributions; private isDark; private embedded; /** Link to a markdown file to render. */ readonly file: i0.InputSignal; /** Markdown string to render. */ readonly data: i0.InputSignal; /** Theme to apply to the markdown content. */ readonly theme: i0.InputSignal; get klass(): string; /** * An event that emit after each rendering pass * with the list of tokens parsed from the input markdown. */ readonly render: i0.OutputEmitterRef; /** * An event that emits once the content has been mounted and revealed (the host * opacity is set to `1`), i.e. after `render` and after embedded components are * mounted. Use it to know the page has actually painted, for example to hide a * loading placeholder without a flash. */ readonly rendered: i0.OutputEmitterRef; constructor(); ngOnInit(): void; ngAfterViewInit(): Promise; ngOnDestroy(): void; private renderContent; private renderFromFile; private renderFromString; private checkTheme; /** Mounts the registered component for every keyword tag present in the rendered output. */ private mountEmbeddedComponents; /** Destroys the components mounted by the previous render so nothing leaks. */ private destroyEmbeddedComponents; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } declare class NgeMarkdownModule { static ɵfac: i0.ɵɵFactoryDeclaration; static ɵmod: i0.ɵɵNgModuleDeclaration; static ɵinj: i0.ɵɵInjectorDeclaration; } /** A configuration feature for {@link provideNgeMarkdown}. */ interface NgeMarkdownFeature { readonly providers: (Provider | EnvironmentProviders)[]; } /** * Configure the markdown renderer at the application root, composing features: * * ```ts * providers: [ * provideNgeMarkdown( * withThemes({ name: 'github', styleUrl: 'assets/nge/markdown/themes/github.css' }), * withKatex(), * withHighlighter(NgeMonacoColorizerService), * ), * ] * ``` */ declare function provideNgeMarkdown(...features: NgeMarkdownFeature[]): EnvironmentProviders; /** Global markdown options (dark theme class name...). */ declare function withConfig(config: NgeMarkdownConfig | (() => NgeMarkdownConfig)): NgeMarkdownFeature; /** Register stylesheet themes; the active one is picked by name. */ declare function withThemes(...themes: NgeMarkdownTheme[]): NgeMarkdownFeature; /** Angular components instantiable from markdown through their custom element tag. */ declare function withComponents(components: NgeMarkdownComponents): NgeMarkdownFeature; /** Render math expressions with [KaTeX](https://katex.org). */ declare function withKatex(options?: NgeMarkdownKatexOptions): NgeMarkdownFeature; /** Render emoji short codes (`:smile:`) with [joypixels](https://www.joypixels.com). */ declare function withEmoji(options?: NgeMarkdownEmojiOptions): NgeMarkdownFeature; /** Render icon short codes (`@mdi/react`-style) inside markdown. */ declare function withIcons(): NgeMarkdownFeature; /** Group content under `=== "Tab"` markers into tabbed sets. */ declare function withTabbedSet(): NgeMarkdownFeature; /** Add anchor links to headings. */ declare function withLinkAnchor(): NgeMarkdownFeature; /** Render `:::` admonition blocks (note, warning...). */ declare function withAdmonitions(): NgeMarkdownFeature; /** * Highlight fenced code blocks. Pass the `NgeMonacoColorizerService` type (from * `@cisstech/nge/monaco`) to colorize with Monaco; it is a parameter, not an * import, so markdown does not depend on monaco. */ declare function withHighlighter(colorizer?: Type): NgeMarkdownFeature; /** * Markdown compiler service. */ declare class NgeMarkdownService { readonly config: NgeMarkdownConfig; private readonly resourceLoader; /** * Compiles a markdown string to an html string. * @param options compilation options. * @returns A promise that resolve with the AST of the compiled markdown * (with the modifications of the contributions). */ compile(options: NgeMarkdownCompileOptions): Promise; private createTransformer; private renderer; private tokenizer; private decodeHtml; private trimIndent; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Parameters of NgeMarkdownService `compile` method. */ interface NgeMarkdownCompileOptions { /** Markdown string to compile. */ markdown: string; /** HTMLElement on which to render the compiled markdown. */ target: HTMLElement; /** Is the markdown contains html code? */ isHtmlString?: boolean; /** List of contribution to use during the compilation. */ contributions?: NgeMarkdownContribution[]; } export { DATA_STACKBLITZ, NGE_MARKDOWN_CODE_ACTIONS, NGE_MARKDOWN_COMPONENTS, NGE_MARKDOWN_CONFIG, NGE_MARKDOWN_CONTRIBUTION, NGE_MARKDOWN_EMOJI_OPTIONS, NGE_MARKDOWN_HIGHLIGHTER_SERVICE, NGE_MARKDOWN_KATEX_OPTIONS, NGE_MARKDOWN_THEMES, NgeMarkdownAdmonitions, NgeMarkdownAdmonitionsProvider, NgeMarkdownComponent, NgeMarkdownComponentsProvider, NgeMarkdownConfigProvider, NgeMarkdownEmoji, NgeMarkdownEmojiOptionsProvider, NgeMarkdownEmojiProvider, NgeMarkdownHighlighter, NgeMarkdownHighlighterMonacoProvider, NgeMarkdownHighlighterProvider, NgeMarkdownIcons, NgeMarkdownIconsProvider, NgeMarkdownKatex, NgeMarkdownKatexOptionsProvider, NgeMarkdownKatexProvider, NgeMarkdownLinkAnchor, NgeMarkdownLinkAnchorProvider, NgeMarkdownModule, NgeMarkdownService, NgeMarkdownTabbedSet, NgeMarkdownTabbedSetProvider, NgeMarkdownThemeProvider, NgeMarkdownTransformer, monacoHighlighterService, provideNgeMarkdown, withAdmonitions, withComponents, withConfig, withEmoji, withHighlighter, withIcons, withKatex, withLinkAnchor, withTabbedSet, withThemes }; export type { NgeMarkdownCodeActionContext, NgeMarkdownCodeActionProvider, NgeMarkdownComponentLoader, NgeMarkdownComponents, NgeMarkdownConfig, NgeMarkdownContribution, NgeMarkdownEmojiOptions, NgeMarkdownFeature, NgeMarkdownHighlightOptions, NgeMarkdownHighlighterService, NgeMarkdownKatexOptions, NgeMarkdownTheme };