| 1 | // Type definitions for turndown 5.0 |
| 2 | // Project: https://github.com/domchristie/turndown |
| 3 | // Definitions by: Sergey Zhidkov <https://github.com/sergey-zhidkov> |
| 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 5 | // TypeScript Version: 2.7 |
| 6 | |
| 7 | declare class TurndownService { |
| 8 | constructor(options?: TurndownService.Options) |
| 9 | |
| 10 | addRule(key: string, rule: TurndownService.Rule): this; |
| 11 | keep(filter: TurndownService.Filter): this; |
| 12 | remove(filter: TurndownService.Filter): this; |
| 13 | use(plugins: TurndownService.Plugin | TurndownService.Plugin[]): this; |
| 14 | escape(str: string): string; |
| 15 | |
| 16 | turndown(html: string | TurndownService.Node): string; |
| 17 | |
| 18 | options: TurndownService.Options; |
| 19 | rules: TurndownService.Rules; |
| 20 | } |
| 21 | |
| 22 | export = TurndownService; |
| 23 | |
| 24 | declare namespace TurndownService { |
| 25 | interface Options { |
| 26 | headingStyle?: "setext" | "atx"; |
| 27 | hr?: string; |
| 28 | br?: string; |
| 29 | bulletListMarker?: "-" | "+" | "*"; |
| 30 | codeBlockStyle?: "indented" | "fenced"; |
| 31 | emDelimiter?: "_" | "*"; |
| 32 | fence?: "```" | "~~~"; |
| 33 | strongDelimiter?: "__" | "**"; |
| 34 | linkStyle?: "inlined" | "referenced"; |
| 35 | linkReferenceStyle?: "full" | "collapsed" | "shortcut"; |
| 36 | |
| 37 | keepReplacement?: ReplacementFunction; |
| 38 | blankReplacement?: ReplacementFunction; |
| 39 | defaultReplacement?: ReplacementFunction; |
| 40 | } |
| 41 | |
| 42 | interface Rule { |
| 43 | filter: Filter; |
| 44 | replacement?: ReplacementFunction; |
| 45 | } |
| 46 | |
| 47 | interface Rules { |
| 48 | options: Options; |
| 49 | array: Rule[]; |
| 50 | |
| 51 | blankRule: ReplacementFunction; |
| 52 | defaultRule: ReplacementFunction; |
| 53 | keepReplacement: ReplacementFunction; |
| 54 | |
| 55 | add(key: Filter, rule: Rule): void; |
| 56 | forEach(callback: (rule: Rule, index: number) => any): void; |
| 57 | forNode(node: Node): Rule; |
| 58 | keep(filter: Filter): void; |
| 59 | remove(filter: Filter): void; |
| 60 | } |
| 61 | |
| 62 | type Plugin = (service: TurndownService) => void; |
| 63 | type Node = HTMLElement | Document | DocumentFragment; |
| 64 | |
| 65 | type Filter = TagName | TagName[] | FilterFunction; |
| 66 | type FilterFunction = (node: HTMLElement, options: Options) => boolean; |
| 67 | |
| 68 | type ReplacementFunction = ( |
| 69 | content: string, |
| 70 | node: Node, |
| 71 | options: Options, |
| 72 | ) => string; |
| 73 | |
| 74 | type TagName = keyof HTMLElementTagNameMap; |
| 75 | } |