import { AnyVirtualDOM, VirtualDOM } from '@youwol/rx-vdom'; import { type Router } from './router'; /** * Type definition for custom view generators. * * The function takes as arguments: * * **elem**: The HTMLElement in Markdown that triggered the generator. * * **options**: The options that were provided to the MD parser. * * It returns the generated virtual DOM. * * See details in the documentation of {@link parseMd} to register views. * */ export type ViewGenerator = (elem: HTMLElement, options: { router?: Router; } & MdParsingOptions) => AnyVirtualDOM; /** * Options for parsing Markdown content. */ export type MdParsingOptions = { /** * Placeholders to account for. A form of preprocessing that replace any occurrences of the keys * in the source by their corresponding values. */ placeholders?: { [k: string]: string; }; /** * Preprocessing step. This callback is called to transform the source before parsing is executed. * @param text original text * @return transformed text */ preprocessing?: (text: string) => string; /** * Custom views generators corresponding to HTMLElement referenced in the Markdown source. */ views?: { [k: string]: ViewGenerator; }; /** * Whether to parse Latex equations. * If `true` the MathJax module needs to be loaded by the consumer before parsing occurs. * * Using the webpm client: * ````js * import { install } from '@youwol/webpm-client' * * await install({ * modules: ['mathjax#^3.1.4'], * }) * ``` * * Within the markdown page, equation blocks are written between `$$` and inline elements between * `\\(` and `\\)` */ latex?: boolean; /** * If true, call {@link Router.emitHtmlUpdated} when the markdown is rendered. */ emitHtmlUpdated?: boolean; }; /** * Represents global Markdown views that can be referenced when using {@link parseMd}. * * By default, it is populated with `code-snippet`, more information in {@link CodeSnippetView}. * * The definition of a custom view is provided using a function that: * * Takes as single argument the HTML element as declared in the markdown file. * The raw text content within the DOM element can be accessed using `elem.textContent` and attributes using * `elem.getAttribute`. * * Returns a virtual dom defining the corresponding implementation of the HTML element. * */ export declare class GlobalMarkdownViews { /** * Static factory for markdown inlined views. */ static factory: { [k: string]: ViewGenerator; }; } /** * Fetch & parse a Markdown file from specified with a URL. * * @param params see {@link MdParsingOptions} for additional options. * @param params.url The URL of the file. */ export declare function fetchMd(params: { url: string; } & MdParsingOptions): ({ router }: { router: Router; }) => Promise>; export declare function fetchMarkdown(p: any): ({ router }: { router: Router; }) => Promise>; export declare function fromMarkdown(p: any): ({ router }: { router: Router; }) => Promise>; /** * Parse a Markdown file specified with a URL. * * Note that custom views provided using the attribute `views ̀ comes in addition to those registered globally in * {@link GlobalMarkdownViews}. * * **Notes on custom views** * * Custom views allow to replace in Markdown sources some elements by dynamically generated ones in javascript. * * * For instance, a custom view `foo-view` can be referenced in the Markdown: * ``` * # An example of custom-view * * This is a custom view: * some content * ``` * When parsed, it will be replaced by its corresponding generated view if `foo-view` is included in this * `views` mapping provided to this function. The associated generator can access attributes (here `barAttr` & * `bazAttr`) as well as the original text content (`some content`). * * The generator functions are called in the order of their corresponding elements in the Markdown source. * * @param args see {@link MdParsingOptions} for additional options. * @param args.src Markdown source. * @param args.router The router instance. * @param args.navigations Specify custom redirections for HTMLAnchorElement. * @returns A virtual DOM encapsulating the parsed Markdown. */ export declare function parseMd({ src, router, navigations, views, placeholders, preprocessing, emitHtmlUpdated, latex, }: { src: string; router?: Router; navigations?: { [k: string]: (e: HTMLAnchorElement) => void; }; } & MdParsingOptions): VirtualDOM<'div'>; export declare function patchSrc({ src, views, idGenerator, }: { src: string; views: any; idGenerator?: () => string; }): { patchedInput: string; contents: {}; }; /** * This function takes an input text, remove the escaped parts: * * a line start with triple back-quote: this line is escaped as well as all the following line until one starts * with triple back-quote. * * a line include a single back quote: the remaining of the line as well as all the following line until a corresponding * single back-quote is found. * * When a part of the input is escaped it is replace by a string `__ESCAPED_${ID}` where ID is a unique ID, * the function returned the escaped text as well as a dict that gathers the escaped elements. */ export declare function removeEscapedText(src: string): { escapedContent: string; replaced: { [k: string]: string; }; };