export = Showdown; export as namespace showdown; /** * Showdown namespace * * @see https://github.com/showdownjs/showdown/blob/master/src/showdown.js */ declare namespace Showdown { /** * Showdown event listener. */ interface EventListener { /** * @param evtName - The event name. * @param text - The current convert value. * @param converter - The converter instance. * @param options - The converter options. * @param globals - A global parsed data of the current conversion. * @returns Can be returned string value to change the current convert value (`text`). * @example * Change by returns string value. * ```ts * let listener: EventListener = (evtName, text, converter, options, globals) => doSome(text); * ``` */ ( evtName: string, text: string, converter: Converter, options: ShowdownOptions, globals: ConverterGlobals, // eslint-disable-next-line @typescript-eslint/no-invalid-void-type ): void | string; } interface ConverterGlobals { converter?: Converter | undefined; gDimensions?: { width?: number | undefined; height?: number | undefined; } | undefined; gHtmlBlocks?: string[] | undefined; gHtmlMdBlocks?: string[] | undefined; gHtmlSpans?: string[] | undefined; gListLevel?: number | undefined; gTitles?: { [key: string]: string } | undefined; gUrls?: { [key: string]: string } | undefined; ghCodeBlocks?: Array<{ codeblock?: string | undefined; text?: string | undefined }> | undefined; hashLinkCounts?: { [key: string]: number } | undefined; langExtensions?: ShowdownExtension[] | undefined; metadata?: { parsed?: { [key: string]: string } | undefined; raw?: string | undefined; format?: string | undefined; } | undefined; outputModifiers?: ShowdownExtension[] | undefined; } interface Extension { /** * Property defines the nature of said sub-extensions and can assume 2 values: * * * `lang` - Language extensions add new markdown syntax to showdown. * * `output` - Output extensions (or modifiers) alter the HTML output generated by showdown. * * `listener` - Listener extensions for listening to a conversion event. */ type: string; /** * Event listeners functions that called on the conversion, when the `event` occurs. */ listeners?: { [event: string]: EventListener } | undefined; } /** * Regex/replace style extensions are very similar to javascript's string.replace function. * Two properties are given, `regex` and `replace`. * * @example * ```ts * let myExt: RegexReplaceExtension = { * type: 'lang', * regex: /markdown/g, * replace: 'showdown' * }; * ``` */ interface RegexReplaceExtension extends Extension { /** * Should be either a string or a RegExp object. * * Keep in mind that, if a string is used, it will automatically be given a g modifier, * that is, it is assumed to be a global replacement. */ regex?: string | RegExp | undefined; /** * Can be either a string or a function. If replace is a string, * it can use the $1 syntax for group substitution, * exactly as if it were making use of string.replace (internally it does this actually). */ replace?: any; // string | Replace } /** * If you'd just like to do everything yourself,you can specify a filter property. * The filter property should be a function that acts as a callback. * * @example * ```ts * let myExt: ShowdownExtension = { * type: 'lang', * filter: (text: string, converter: Converter) => text.replace('#', '*') * }; * ``` */ interface FilterExtension extends Extension { filter?: ((text: string, converter: Converter, options?: ConverterOptions) => string) | undefined; } /** * Defines a plugin/extension * Each single extension can be one of two types: * * + Language Extension -- Language extensions are ones that that add new markdown syntax to showdown. For example, say you wanted ^^youtube http://www.youtube.com/watch?v=oHg5SJYRHA0 to automatically render as an embedded YouTube video, that would be a language extension. * + Output Modifiers -- After showdown has run, and generated HTML, an output modifier would change that HTML. For example, say you wanted to change
var foo = 'bar';
*
* ```
* **omitExtraWLInCodeBlocks** = true:
*
* ```html
* var foo = 'bar';
* ```
* @default false
* @since 1.0.0
*/
omitExtraWLInCodeBlocks?: boolean | undefined;
/**
* Disable the automatic generation of header ids.
* Showdown generates an id for headings automatically. This is useful for linking to a specific header.
* This behavior, however, can be disabled with this option.
*
* @example
* **input**:
*
* ```md
* # This is a header
* ```
*
* **noHeaderId** = false
*
* ```html
* some text www.google.com
* ``` * * **simplifiedAutoLink** = true * * ```html *some text www.google.com
* ``` * @default false * @since 1.2.0 */ simplifiedAutoLink?: boolean | undefined; /** * @deprecated https://github.com/showdownjs/showdown/commit/d3ebff7ef0cde5abfc3874463946d5297fc82e78 * * This option excludes trailing punctuation from autolinking urls. * Punctuation excluded: . ! ? ( ). * * @remarks This option only applies to links generated by {@link Showdown.ShowdownOptions.simplifiedAutoLink}. * @example * **input**: * * ```md * check this link www.google.com. * ``` * * **excludeTrailingPunctuationFromURLs** = false * * ```html *check this link www.google.com.
* ``` * * **excludeTrailingPunctuationFromURLs** = true * * ```html *check this link www.google.com.
* ``` * @default false * @since 1.5.1 */ excludeTrailingPunctuationFromURLs?: boolean | undefined; /** * Turning this on will stop showdown from interpreting underscores in the middle of * words as and and instead treat them as literal underscores. * * @example * **input**: * * ```md * some text with__underscores__in middle * ``` * * **literalMidWordUnderscores** = false * * ```html *some text withunderscoresin middle
* ``` * * **literalMidWordUnderscores** = true * * ```html *some text with__underscores__in middle
* ``` * @default false * @since 1.2.0 */ literalMidWordUnderscores?: boolean | undefined; /** * Enable support for strikethrough syntax. * * @example * **syntax**: * * ```md * ~~strikethrough~~ * ``` * * ```html *...
*...
*a line * wrapped in two
* ``` * * **simpleLineBreaks** = true * * ```html *a line
* wrapped in two
#header
* ``` * * @default false * @since 1.5.3 */ requireSpaceBeforeHeadingText?: boolean | undefined; /** * Enables support for github @mentions, which links to the github profile page of the username mentioned. * * @example * **input**: * * ```md * hello there @tivie * ``` * * **ghMentions** = false * * ```html *hello there @tivie
* ``` * * **ghMentions** = true * * ```html *hello there @tivie
* ``` * * **ghMentionsLink** = http://mysite.com/{u}/profile * * ```html *hello there @tivie
* ``` * @default https://github.com/{u} * @since 1.6.2 */ ghMentionsLink?: string | undefined; /** * Enables e-mail addresses encoding through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities. * * @remarks Prior to version 1.6.1, emails would always be obfuscated through dec and hex encoding. * @example * **input**: * * ``` *\
<div>foo</div>
* ``` * @default false * @since 1.7.2 */ backslashEscapesHTMLTags?: boolean | undefined; /** * Enable emoji support. * * @example * ```md * this is a :smile: emoji * ``` * @default false * @see https://github.com/showdownjs/showdown/wiki/Emojis * @since 1.8.0 */ emoji?: boolean | undefined; /** * Enable support for underline. Syntax is double or triple underscores: `__underline word__`. With this option enabled, * underscores no longer parses into `` and `` * * @example * **input**: * * ```md * __underline word__ * ``` * * **underline** = false * ```html *underlined word
* ``` * * **underline** = true * ```html *underlined word
* ``` * @default false * @since 1.8.0 */ underline?: boolean | undefined; /** * Replaces three dots with the ellipsis unicode character. * @default true */ ellipsis?: boolean | undefined; /** * Outputs a complete html document, including , and tags' instead of an HTML fragment. * * @example * **input**: * * ```md * # Showdown * ``` * * **completeHTMLDocument** = false * ```html *Showdown
* ``` * * **completeHTMLDocument** = true * ```html * * * * * * *Showdown
* * * ``` * @default false * @since 1.8.5 */ completeHTMLDocument?: boolean | undefined; /** * Enable support for document metadata (defined at the top of the document * between `«««` and `»»»` or between `---` and `---`). * * @example * ```js * var conv = new showdown.Converter({metadata: true}); * var html = conv.makeHtml(someMd); * var metadata = conv.getMetadata(); // returns an object with the document metadata * ``` * @default false * @since 1.8.5 */ metadata?: boolean | undefined; /** * Split adjacent blockquote blocks. * * @since 1.8.6 */ splitAdjacentBlockquotes?: boolean | undefined; /** * For custom options {extension, subParser} And also an out-of-date definitions */ [key: string]: any; } interface ConverterOptions extends ShowdownOptions { /** * Add extensions to the new converter can be showdown extensions or "global" extensions name. */ extensions?: | Array<(() => ShowdownExtension[] | ShowdownExtension) | ShowdownExtension[] | ShowdownExtension | string> | undefined; } /** * Showdown Flavor names. */ type Flavor = "github" | "original" | "ghost" | "vanilla" | "allOn"; /** * Showdown option description. */ interface ShowdownOptionDescription { /** * The default value of option. */ defaultValue?: boolean | undefined; /** * The description of the option. */ description?: string | undefined; /** * The type of the option value. */ type?: "boolean" | "string" | "integer" | undefined; } /** * Showdown options schema. */ interface ShowdownOptionsSchema { [key: string]: ShowdownOptionDescription; } /** * Showdown subParser. */ type SubParser = (...args: any[]) => string; /** * Showdown Converter prototype. * * @see https://github.com/showdownjs/showdown/blob/master/src/converter.js */ interface Converter { /** * Listen to an event. * * @param name - The event name. * @param callback - The function that will be called when the event occurs. * @throws Throws if the type of `name` is not string. * @throws Throws if the type of `callback` is not function. * @example * ```ts * let converter: Converter = new Converter(); * converter * .listen('hashBlock.before', (evtName, text, converter, options, globals) => { * // ... do stuff to text ... * return text; * }) * .makeHtml('...'); * ``` */ listen(name: string, callback: EventListener): Converter; /** * Converts a markdown string into HTML string. * * @param text - The input text (markdown). * @return The output HTML. */ makeHtml(text: string): string; /** * Converts an HTML string into a markdown string. * * @param src - The input text (HTML) * @param [HTMLParser] A WHATWG DOM and HTML parser, such as JSDOM. If none is supplied, window.document will be used. * @returns The output markdown. */ makeMarkdown(src: string, HTMLParser?: HTMLDocument): string; /** * Setting a "local" option only affects the specified Converter object. * * @param key - The key of the option. * @param value - The value of the option. */ setOption(key: string, value: any): void; /** * Get the option of this Converter instance. * * @param key - The key of the option. * @returns Returns the value of the given `key`. */ getOption(key: string): any; /** * Get the options of this Converter instance. * * @returns Returns the current convertor options object. */ getOptions(): ShowdownOptions; /** * Add extension to THIS converter. * * @param extension - The new extension to add. * @param name - The extension name. */ addExtension( extension: (() => ShowdownExtension[] | ShowdownExtension) | ShowdownExtension[] | ShowdownExtension, name?: string, ): void; /** * Use a global registered extension with THIS converter. * * @param extensionName - Name of the previously registered extension. */ useExtension(extensionName: string): void; /** * Set a "local" flavor for THIS Converter instance. * * @param flavor - The flavor name. */ setFlavor(name: Flavor): void; /** * Get the "local" currently set flavor of this converter. * * @returns Returns string flavor name. */ getFlavor(): Flavor; /** * Remove an extension from THIS converter. * * @remarks This is a costly operation. It's better to initialize a new converter. * and specify the extensions you wish to use. * @param extensions - The extensions to remove. */ removeExtension(extensions: ShowdownExtension[] | ShowdownExtension): void; /** * Get all extensions. * * @return all extensions. */ getAllExtensions(): ConverterExtensions; /** * Get the metadata of the previously parsed document. * * @param raw - If to returns Row or Metadata. * @returns Returns Row if `row` is `true`, otherwise Metadata. */ getMetadata(raw?: boolean): string | Metadata; /** * Get the metadata format of the previously parsed document. * * @returns Returns the metadata format. */ getMetadataFormat(): string; } interface ConverterStatic { /** * @param converterOptions - Configuration object, describes which extensions to apply. */ new(converterOptions?: ConverterOptions): Converter; } /** * Helper Interface */ interface Helper { replaceRecursiveRegExp(...args: any[]): string; [key: string]: (...args: any[]) => any; } /** * Constructor function for a Converter. */ var Converter: ConverterStatic; /** * Showdown helper. */ var helper: Helper; /** * Showdown extensions. */ var extensions: ShowdownExtensions; /** * Setting a "global" option affects all instances of showdown. * * @param key - the option key. * @param value - the option value. */ function setOption(key: string, value: any): typeof Showdown; /** * Get a "global" option. * * @param key - the option key. * @returns Returns the value of the given `key`. */ function getOption(key: string): any; /** * Get the "global" options. * * @returns Returns a options object. */ function getOptions(): ShowdownOptions; /** * Reset "global" options to the default values. */ function resetOptions(): void; /** * Setting a "global" flavor affects all instances of showdown. * * @param name - The flavor name. */ function setFlavor(name: Flavor): void; /** * Get the "global" currently set flavor. * * @returns Returns string flavor name. */ function getFlavor(): Flavor; /** * Get the options of a specified flavor. Returns undefined if the flavor was not found. * * @param name - Name of the flavor. * @returns Returns options object of the given flavor `name`. */ function getFlavorOptions(name: Flavor): ShowdownOptions | undefined; /** * Get the default options. * * @param [simple=true] - If to returns the default showdown options or the showdown options schema. * @returns Returns the options schema if `simple` is `false`, otherwise the default showdown options. */ function getDefaultOptions(simple?: boolean): ShowdownOptionsSchema | ShowdownOptions; /** * Get a registered subParser. * * @param name - The parser name. * @returns Returns the parser of the given `name`. * @throws Throws if `name` is not of type string. * @throws Throws if the parser is not exists. */ function subParser(name: string): SubParser; /** * Register a subParser. * * @param name - The name of the new parser. * @param func - The handler function of the new parser. * @throws Throws if `name` is not of type string. */ function subParser(name: string, func: SubParser): void; /** * Get a registered extension. * * @param name - The extension name. * @returns Returns the extension of the given `name`. * @throws Throws if `name` is not of type string. * @throws Throws if the extension is not exists. */ function extension(name: string): ShowdownExtension[]; /** * Register a extension. * * @param name - The name of the new extension. * @param ext - The extension. * @throws Throws if `name` is not of type string. */ function extension( name: string, ext: (() => ShowdownExtension[] | ShowdownExtension) | ShowdownExtension[] | ShowdownExtension, ): void; /** * Get the "global" extensions. * * @return Returns all extensions. */ function getAllExtensions(): ShowdownExtensions; /** * Remove an extension. * * @param name - The extension name. */ function removeExtension(name: string): void; /** * Removes all extensions. */ function resetExtensions(): void; /** * Checks if the given `ext` is a valid showdown extension. * * @param ext - The extension to checks. * @returns Returns `true` if the extension is valid showdown extension, otherwise `false`. */ function validateExtension(ext: ShowdownExtension[] | ShowdownExtension): boolean; }