showdown.d.ts 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. // Type definitions for Showdown 1.9.0
  2. // Project: https://github.com/showdownjs/showdown
  3. // Definitions by: Hamed Baatour <https://github.com/hamedbaatour>,
  4. // cbowdon <https://github.com/cbowdon>,
  5. // Pei-Tang Huang <https://github.com/tan9>,
  6. // Ariel-Saldana <https://github.com/arielsaldana>,
  7. // Yisrael Eliav <https://github.com/yisraelx>
  8. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  9. export = Showdown;
  10. export as namespace showdown;
  11. /**
  12. * Showdown namespace
  13. *
  14. * @see https://github.com/showdownjs/showdown/blob/master/src/showdown.js
  15. */
  16. declare namespace Showdown {
  17. /**
  18. * Showdown event listener.
  19. */
  20. interface EventListener {
  21. /**
  22. * @param evtName - The event name.
  23. * @param text - The current convert value.
  24. * @param converter - The converter instance.
  25. * @param options - The converter options.
  26. * @param globals - A global parsed data of the current conversion.
  27. * @returns Can be returned string value to change the current convert value (`text`).
  28. * @example
  29. * Change by returns string value.
  30. * ```ts
  31. * let listener: EventListener = (evtName, text, converter, options, globals) => doSome(text);
  32. * ```
  33. */
  34. (evtName: string, text: string, converter: Converter, options: ShowdownOptions, globals: ConverterGlobals): void | string;
  35. }
  36. interface ConverterGlobals {
  37. converter?: Converter;
  38. gDimensions?: {
  39. width?: number;
  40. height?: number;
  41. };
  42. gHtmlBlocks?: string[];
  43. gHtmlMdBlocks?: string[];
  44. gHtmlSpans?: string[];
  45. gListLevel?: number;
  46. gTitles?: {[key: string]: string};
  47. gUrls?: {[key: string]: string};
  48. ghCodeBlocks?: {codeblock?: string, text?: string}[];
  49. hashLinkCounts?: {[key: string]: number};
  50. langExtensions?: ShowdownExtension[];
  51. metadata?: {
  52. parsed?: {[key: string]: string};
  53. raw?: string;
  54. format?: string;
  55. };
  56. outputModifiers?: ShowdownExtension[];
  57. }
  58. interface Extension {
  59. /**
  60. * Property defines the nature of said sub-extensions and can assume 2 values:
  61. *
  62. * * `lang` - Language extensions add new markdown syntax to showdown.
  63. * * `output` - Output extensions (or modifiers) alter the HTML output generated by showdown.
  64. * * `listener` - Listener extensions for listening to a conversion event.
  65. */
  66. type: string;
  67. /**
  68. * Event listeners functions that called on the conversion, when the `event` occurs.
  69. */
  70. listeners?: {[event: string]: EventListener}
  71. }
  72. /**
  73. * Regex/replace style extensions are very similar to javascript's string.replace function.
  74. * Two properties are given, `regex` and `replace`.
  75. *
  76. * @example
  77. * ```ts
  78. * let myExt: RegexReplaceExtension = {
  79. * type: 'lang',
  80. * regex: /markdown/g,
  81. * replace: 'showdown'
  82. * };
  83. * ```
  84. */
  85. interface RegexReplaceExtension extends Extension {
  86. /**
  87. * Should be either a string or a RegExp object.
  88. *
  89. * Keep in mind that, if a string is used, it will automatically be given a g modifier,
  90. * that is, it is assumed to be a global replacement.
  91. */
  92. regex?: string | RegExp;
  93. /**
  94. * Can be either a string or a function. If replace is a string,
  95. * it can use the $1 syntax for group substitution,
  96. * exactly as if it were making use of string.replace (internally it does this actually).
  97. */
  98. replace?: any; // string | Replace
  99. }
  100. /**
  101. * If you'd just like to do everything yourself,you can specify a filter property.
  102. * The filter property should be a function that acts as a callback.
  103. *
  104. * @example
  105. * ```ts
  106. * let myExt: ShowdownExtension = {
  107. * type: 'lang',
  108. * filter: (text: string, converter: Converter) => text.replace('#', '*')
  109. * };
  110. * ```
  111. */
  112. interface FilterExtension extends Extension {
  113. filter?: (text: string, converter: Converter, options?: ConverterOptions) => string;
  114. }
  115. /**
  116. * Defines a plugin/extension
  117. * Each single extension can be one of two types:
  118. *
  119. * + 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.
  120. * + Output Modifiers -- After showdown has run, and generated HTML, an output modifier would change that HTML. For example, say you wanted to change <div class="header"> to be <header>, that would be an output modifier.
  121. * + Listener Extension -- Listener extensions for listen to conversion events.
  122. *
  123. * Each extension can provide two combinations of interfaces for showdown.
  124. *
  125. * @example
  126. * ```ts
  127. * let myext: ShowdownExtension = {
  128. * type: 'output',
  129. * filter(text, converter, options) {
  130. * // ... do stuff to text ...
  131. * return text;
  132. * },
  133. * listeners: {
  134. * ['lists.after'](evtName, text, converter, options, globals){
  135. * // ... do stuff to text ...
  136. * return text;
  137. * },
  138. * // ...
  139. * }
  140. * };
  141. * ```
  142. */
  143. interface ShowdownExtension extends RegexReplaceExtension, FilterExtension {
  144. }
  145. /**
  146. * Showdown extensions store object.
  147. */
  148. interface ShowdownExtensions {
  149. [name: string]: ShowdownExtension[]
  150. }
  151. /**
  152. * Showdown converter extensions store object.
  153. */
  154. interface ConverterExtensions {
  155. language: ShowdownExtension[];
  156. output: ShowdownExtension[];
  157. }
  158. interface Metadata {
  159. [meta: string]: string;
  160. }
  161. /**
  162. * Showdown options.
  163. *
  164. * @see https://github.com/showdownjs/showdown#valid-options
  165. * @see https://github.com/showdownjs/showdown/wiki/Showdown-options
  166. * @see https://github.com/showdownjs/showdown/blob/master/src/options.js
  167. */
  168. interface ShowdownOptions {
  169. /**
  170. * Omit the trailing newline in a code block.
  171. * By default, showdown adds a newline before the closing tags in code blocks. By enabling this option, that newline is removed.
  172. * This option affects both indented and fenced (gfm style) code blocks.
  173. *
  174. * @example
  175. *
  176. * **input**:
  177. *
  178. * ```md
  179. * var foo = 'bar';
  180. * ```
  181. *
  182. * **omitExtraWLInCodeBlocks** = false:
  183. *
  184. * ```html
  185. * <code><pre>var foo = 'bar';
  186. * </pre></code>
  187. * ```
  188. * **omitExtraWLInCodeBlocks** = true:
  189. *
  190. * ```html
  191. * <code><pre>var foo = 'bar';</pre></code>
  192. * ```
  193. * @default false
  194. * @since 1.0.0
  195. */
  196. omitExtraWLInCodeBlocks?: boolean;
  197. /**
  198. * Disable the automatic generation of header ids.
  199. * Showdown generates an id for headings automatically. This is useful for linking to a specific header.
  200. * This behavior, however, can be disabled with this option.
  201. *
  202. * @example
  203. * **input**:
  204. *
  205. * ```md
  206. * # This is a header
  207. * ```
  208. *
  209. * **noHeaderId** = false
  210. *
  211. * ```html
  212. * <h1 id="thisisaheader">This is a header</h1>
  213. * ```
  214. *
  215. * **noHeaderId** = true
  216. *
  217. * ```html
  218. * <h1>This is a header</h1>
  219. * ```
  220. * @default false
  221. * @since 1.1.0
  222. */
  223. noHeaderId?: boolean;
  224. /**
  225. * Use text in curly braces as header id.
  226. *
  227. * @example
  228. * ```md
  229. * ## Sample header {real-id} will use real-id as id
  230. * ```
  231. * @default false
  232. * @since 1.7.0
  233. */
  234. customizedHeaderId?: boolean;
  235. /**
  236. * Generate header ids compatible with github style (spaces are replaced
  237. * with dashes and a bunch of non alphanumeric chars are removed).
  238. *
  239. * @example
  240. * **input**:
  241. *
  242. * ```md
  243. * # This is a header with @#$%
  244. * ```
  245. *
  246. * **ghCompatibleHeaderId** = false
  247. *
  248. * ```html
  249. * <h1 id="thisisaheader">This is a header</h1>
  250. * ```
  251. *
  252. * **ghCompatibleHeaderId** = true
  253. *
  254. * ```html
  255. * <h1 id="this-is-a-header-with-">This is a header with @#$%</h1>
  256. * ```
  257. * @default false
  258. * @since 1.5.5
  259. */
  260. ghCompatibleHeaderId?: boolean;
  261. /**
  262. * Add a prefix to the generated header ids.
  263. * Passing a string will prefix that string to the header id.
  264. * Setting to true will add a generic 'section' prefix.
  265. *
  266. * @default false
  267. * @since 1.0.0
  268. */
  269. prefixHeaderId?: string | boolean;
  270. /**
  271. * Setting this option to true will prevent showdown from modifying the prefix.
  272. * This might result in malformed IDs (if, for instance, the " char is used in the prefix).
  273. * Has no effect if prefixHeaderId is set to false.
  274. *
  275. * @default false
  276. * @since 1.7.3
  277. */
  278. rawPrefixHeaderId?: boolean;
  279. /**
  280. * Remove only spaces, ' and " from generated header ids (including prefixes),
  281. * replacing them with dashes (-).
  282. * WARNING: This might result in malformed ids.
  283. *
  284. * @default false
  285. * @since 1.7.3
  286. */
  287. rawHeaderId?: boolean;
  288. /**
  289. * Enable support for setting image dimensions from within markdown syntax.
  290. *
  291. * @example
  292. * ```md
  293. * ![foo](foo.jpg =100x80) simple, assumes units are in px
  294. * ![bar](bar.jpg =100x*) sets the height to "auto"
  295. * ![baz](baz.jpg =80%x5em) Image with width of 80% and height of 5em
  296. * ```
  297. * @default false
  298. * @since 1.1.0
  299. */
  300. parseImgDimensions?: boolean;
  301. /**
  302. * Set the header starting level. For instance, setting this to 3 means that
  303. *
  304. * @example
  305. * **input**:
  306. *
  307. * ```md
  308. * # header
  309. * ```
  310. *
  311. * **headerLevelStart** = 1
  312. *
  313. * ```html
  314. * <h1>header</h1>
  315. * ```
  316. *
  317. * **headerLevelStart** = 3
  318. *
  319. * ```html
  320. * <h3>header</h3>
  321. * ```
  322. * @default 1
  323. * @since 1.1.0
  324. */
  325. headerLevelStart?: number;
  326. /**
  327. * Turning this option on will enable automatic linking to urls.
  328. *
  329. * @example
  330. * **input**:
  331. *
  332. * ```md
  333. * some text www.google.com
  334. * ```
  335. *
  336. * **simplifiedAutoLink** = false
  337. *
  338. * ```html
  339. * <p>some text www.google.com</p>
  340. * ```
  341. *
  342. * **simplifiedAutoLink** = true
  343. *
  344. * ```html
  345. * <p>some text <a href="www.google.com">www.google.com</a></p>
  346. * ```
  347. * @default false
  348. * @since 1.2.0
  349. */
  350. simplifiedAutoLink?: boolean;
  351. /**
  352. * @deprecated https://github.com/showdownjs/showdown/commit/d3ebff7ef0cde5abfc3874463946d5297fc82e78
  353. *
  354. * This option excludes trailing punctuation from autolinking urls.
  355. * Punctuation excluded: . ! ? ( ).
  356. *
  357. * @remarks This option only applies to links generated by {@link Showdown.ShowdownOptions.simplifiedAutoLink}.
  358. * @example
  359. * **input**:
  360. *
  361. * ```md
  362. * check this link www.google.com.
  363. * ```
  364. *
  365. * **excludeTrailingPunctuationFromURLs** = false
  366. *
  367. * ```html
  368. * <p>check this link <a href="www.google.com">www.google.com.</a></p>
  369. * ```
  370. *
  371. * **excludeTrailingPunctuationFromURLs** = true
  372. *
  373. * ```html
  374. * <p>check this link <a href="www.google.com">www.google.com</a>.</p>
  375. * ```
  376. * @default false
  377. * @since 1.5.1
  378. */
  379. excludeTrailingPunctuationFromURLs?: boolean;
  380. /**
  381. * Turning this on will stop showdown from interpreting underscores in the middle of
  382. * words as <em> and <strong> and instead treat them as literal underscores.
  383. *
  384. * @example
  385. * **input**:
  386. *
  387. * ```md
  388. * some text with__underscores__in middle
  389. * ```
  390. *
  391. * **literalMidWordUnderscores** = false
  392. *
  393. * ```html
  394. * <p>some text with<strong>underscores</strong>in middle</p>
  395. * ```
  396. *
  397. * **literalMidWordUnderscores** = true
  398. *
  399. * ```html
  400. * <p>some text with__underscores__in middle</p>
  401. * ```
  402. * @default false
  403. * @since 1.2.0
  404. */
  405. literalMidWordUnderscores?: boolean;
  406. /**
  407. * Enable support for strikethrough syntax.
  408. *
  409. * @example
  410. * **syntax**:
  411. *
  412. * ```md
  413. * ~~strikethrough~~
  414. * ```
  415. *
  416. * ```html
  417. * <del>strikethrough</del>
  418. * ```
  419. * @default false
  420. * @since 1.2.0
  421. */
  422. strikethrough?: boolean;
  423. /**
  424. * Enable support for tables syntax.
  425. *
  426. * @example
  427. * **syntax**:
  428. *
  429. * ```md
  430. * | h1 | h2 | h3 |
  431. * |:------|:-------:|--------:|
  432. * | 100 | [a][1] | ![b][2] |
  433. * | *foo* | **bar** | ~~baz~~ |
  434. * ```
  435. * @default false
  436. * @since 1.2.0
  437. */
  438. tables?: boolean;
  439. /**
  440. * If enabled adds an id property to table headers tags.
  441. *
  442. * @remarks This options only applies if **[tables][]** is enabled.
  443. * @default false
  444. * @since 1.2.0
  445. */
  446. tablesHeaderId?: boolean;
  447. /**
  448. * Enable support for GFM code block style syntax (fenced codeblocks).
  449. *
  450. * @example
  451. * **syntax**:
  452. *
  453. * ```md
  454. * some code here
  455. * ```
  456. * @default true
  457. * @since 1.2.0
  458. */
  459. ghCodeBlocks?: boolean;
  460. /**
  461. * Enable support for GFM takslists.
  462. *
  463. * @example
  464. * **syntax**:
  465. *
  466. * ```md
  467. * - [x] This task is done
  468. * - [ ] This is still pending
  469. * ```
  470. * @default false
  471. * @since 1.2.0
  472. */
  473. tasklists?: boolean;
  474. /**
  475. * Prevents weird effects in live previews due to incomplete input.
  476. *
  477. * @example
  478. * ![awkward effect](http://i.imgur.com/YQ9iHTL.gif)
  479. * You can prevent this by enabling this option.
  480. * @default false
  481. */
  482. smoothLivePreview?: boolean;
  483. /**
  484. * Tries to smartly fix indentation problems related to es6 template
  485. * strings in the midst of indented code.
  486. *
  487. * @default false
  488. * @since 1.4.2
  489. */
  490. smartIndentationFix?: boolean;
  491. /**
  492. * Disables the requirement of indenting sublists by 4 spaces for them to be nested,
  493. * effectively reverting to the old behavior where 2 or 3 spaces were enough.
  494. *
  495. * @example
  496. * **input**:
  497. *
  498. * ```md
  499. * - one
  500. * - two
  501. *
  502. * ...
  503. *
  504. * - one
  505. * - two
  506. * ```
  507. *
  508. * **disableForced4SpacesIndentedSublists** = false
  509. *
  510. * ```html
  511. * <ul>
  512. * <li>one</li>
  513. * <li>two</li>
  514. * </ul>
  515. * <p>...</p>
  516. * <ul>
  517. * <li>one
  518. * <ul>
  519. * <li>two</li>
  520. * </ul>
  521. * </li>
  522. * </ul>
  523. * ```
  524. *
  525. * **disableForced4SpacesIndentedSublists** = true
  526. *
  527. * ```html
  528. * <ul>
  529. * <li>one
  530. * <ul>
  531. * <li>two</li>
  532. * </ul>
  533. * </li>
  534. * </ul>
  535. * <p>...</p>
  536. * <ul>
  537. * <li>one
  538. * <ul>
  539. * <li>two</li>
  540. * </ul>
  541. * </li>
  542. * </ul>
  543. * ```
  544. * @default false
  545. * @since 1.5.0
  546. */
  547. disableForced4SpacesIndentedSublists?: boolean;
  548. /**
  549. * Parses line breaks as like GitHub does, without needing 2 spaces at the end of the line.
  550. *
  551. * @example
  552. * **input**:
  553. *
  554. * ```md
  555. * a line
  556. * wrapped in two
  557. * ```
  558. *
  559. * **simpleLineBreaks** = false
  560. *
  561. * ```html
  562. * <p>a line
  563. * wrapped in two</p>
  564. * ```
  565. *
  566. * **simpleLineBreaks** = true
  567. *
  568. * ```html
  569. * <p>a line<br>
  570. * wrapped in two</p>
  571. * ```
  572. * @default false
  573. * @since 1.5.1
  574. */
  575. simpleLineBreaks?: boolean;
  576. /**
  577. * Makes adding a space between # and the header text mandatory.
  578. *
  579. * @example
  580. * **input**:
  581. *
  582. * ```md
  583. * #header
  584. * ```
  585. *
  586. * **requireSpaceBeforeHeadingText** = false
  587. *
  588. * ```html
  589. * <h1 id="header">header</h1>
  590. * ```
  591. *
  592. * **simpleLineBreaks** = true
  593. *
  594. * ```html
  595. * <p>#header</p>
  596. * ```
  597. *
  598. * @default false
  599. * @since 1.5.3
  600. */
  601. requireSpaceBeforeHeadingText?: boolean;
  602. /**
  603. * Enables support for github @mentions, which links to the github profile page of the username mentioned.
  604. *
  605. * @example
  606. * **input**:
  607. *
  608. * ```md
  609. * hello there @tivie
  610. * ```
  611. *
  612. * **ghMentions** = false
  613. *
  614. * ```html
  615. * <p>hello there @tivie</p>
  616. * ```
  617. *
  618. * **ghMentions** = true
  619. *
  620. * ```html
  621. * <p>hello there <a href="https://www.github.com/tivie>@tivie</a></p>
  622. * ```
  623. * @default false
  624. * @since 1.6.0
  625. */
  626. ghMentions?: boolean;
  627. /**
  628. * Changes the link generated by @mentions. `{u}` is replaced by the text of the mentions. Only applies if **[ghMentions][]** is enabled.
  629. *
  630. * @example
  631. * **input**:
  632. *
  633. * ```md
  634. * hello there @tivie
  635. * ```
  636. *
  637. * **ghMentionsLink** = https://github.com/{u}
  638. *
  639. * ```html
  640. * <p>hello there <a href="https://www.github.com/tivie>@tivie</a></p>
  641. * ```
  642. *
  643. * **ghMentionsLink** = http://mysite.com/{u}/profile
  644. *
  645. * ```html
  646. * <p>hello there <a href="//mysite.com/tivie/profile">@tivie</a></p>
  647. * ```
  648. * @default https://github.com/{u}
  649. * @since 1.6.2
  650. */
  651. ghMentionsLink?: string;
  652. /**
  653. * Enables e-mail addresses encoding through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities.
  654. *
  655. * @remarks Prior to version 1.6.1, emails would always be obfuscated through dec and hex encoding.
  656. * @example
  657. * **input**:
  658. *
  659. * ```
  660. * <[email protected]>
  661. * ```
  662. *
  663. * **encodeEmails** = false
  664. *
  665. * ```html
  666. * <a href="mailto:[email protected]">[email protected]</a>
  667. * ```
  668. *
  669. * **encodeEmails** = true
  670. *
  671. * ```html
  672. * <a href="&#109;&#97;&#105;&#108;t&#x6f;&#x3a;&#109;&#x79;s&#x65;&#x6c;&#102;&#64;&#x65;xa&#109;&#112;&#108;&#101;&#x2e;c&#x6f;&#109;">&#x6d;&#121;s&#101;&#108;f&#x40;&#x65;&#120;a&#x6d;&#x70;&#108;&#x65;&#x2e;&#99;&#x6f;&#109;</a>
  673. * ```
  674. * @default true
  675. * @since 1.6.1
  676. */
  677. encodeEmails?: boolean;
  678. /**
  679. * Open all links in new windows (by adding the attribute target="_blank" to <a> tags).
  680. *
  681. * @example
  682. * **input**:
  683. *
  684. * ```md
  685. * [Showdown](http://showdownjs.com)
  686. * ```
  687. *
  688. * **openLinksInNewWindow** = false
  689. * ```html
  690. * <p><a href="http://showdownjs.com">Showdown</a></p>
  691. * ```
  692. *
  693. * **openLinksInNewWindow** = true
  694. * ```html
  695. * <p><a href="http://showdownjs.com" target="_blank">Showdown</a></p>
  696. * ```
  697. * @default false
  698. * @since 1.7.0
  699. */
  700. openLinksInNewWindow?: boolean;
  701. /**
  702. * Support for HTML Tag escaping.
  703. *
  704. * @example
  705. * **input**:
  706. *
  707. * ```md
  708. * \<div>foo\</div>.
  709. * ```
  710. *
  711. * **backslashEscapesHTMLTags** = false
  712. * ```html
  713. * <p>\<div>foo\</div></p>
  714. * ```
  715. *
  716. * **backslashEscapesHTMLTags** = true
  717. * ```html
  718. * <p>&lt;div&gt;foo&lt;/div&gt;</p>
  719. * ```
  720. * @default false
  721. * @since 1.7.2
  722. */
  723. backslashEscapesHTMLTags?: boolean;
  724. /**
  725. * Enable emoji support.
  726. *
  727. * @example
  728. * ```md
  729. * this is a :smile: emoji
  730. * ```
  731. * @default false
  732. * @see https://github.com/showdownjs/showdown/wiki/Emojis
  733. * @since 1.8.0
  734. */
  735. emoji?: boolean;
  736. /**
  737. * Enable support for underline. Syntax is double or triple underscores: `__underline word__`. With this option enabled,
  738. * underscores no longer parses into `<em>` and `<strong>`
  739. *
  740. * @example
  741. * **input**:
  742. *
  743. * ```md
  744. * __underline word__
  745. * ```
  746. *
  747. * **underline** = false
  748. * ```html
  749. * <p><strong>underlined word</strong></p>
  750. * ```
  751. *
  752. * **underline** = true
  753. * ```html
  754. * <p><u>underlined word</u></p>
  755. * ```
  756. * @default false
  757. * @since 1.8.0
  758. */
  759. underline?: boolean;
  760. /**
  761. * Outputs a complete html document, including <html>, <head> and <body> tags' instead of an HTML fragment.
  762. *
  763. * @example
  764. * **input**:
  765. *
  766. * ```md
  767. * # Showdown
  768. * ```
  769. *
  770. * **completeHTMLDocument** = false
  771. * ```html
  772. * <p><strong>Showdown</strong></p>
  773. * ```
  774. *
  775. * **completeHTMLDocument** = true
  776. * ```html
  777. * <!DOCTYPE HTML>
  778. * <html>
  779. * <head>
  780. * <meta charset="utf-8">
  781. * </head>
  782. * <body>
  783. * <p><strong>Showdown</strong></p>
  784. * </body>
  785. * </html>
  786. * ```
  787. * @default false
  788. * @since 1.8.5
  789. */
  790. completeHTMLDocument?: boolean;
  791. /**
  792. * Enable support for document metadata (defined at the top of the document
  793. * between `«««` and `»»»` or between `---` and `---`).
  794. *
  795. * @example
  796. * ```js
  797. * var conv = new showdown.Converter({metadata: true});
  798. * var html = conv.makeHtml(someMd);
  799. * var metadata = conv.getMetadata(); // returns an object with the document metadata
  800. * ```
  801. * @default false
  802. * @since 1.8.5
  803. */
  804. metadata?: boolean;
  805. /**
  806. * Split adjacent blockquote blocks.
  807. *
  808. * @since 1.8.6
  809. */
  810. splitAdjacentBlockquotes?: boolean;
  811. /**
  812. * For custom options {extension, subParser} And also an out-of-date definitions
  813. */
  814. [key:string]: any;
  815. }
  816. interface ConverterOptions extends ShowdownOptions {
  817. /**
  818. * Add extensions to the new converter can be showdown extensions or "global" extensions name.
  819. */
  820. extensions?: ((() => ShowdownExtension[] | ShowdownExtension) | ShowdownExtension[] | ShowdownExtension | string)[];
  821. }
  822. /**
  823. * Showdown Flavor names.
  824. */
  825. type Flavor = 'github' | 'original' | 'ghost' | 'vanilla' | 'allOn';
  826. /**
  827. * Showdown option description.
  828. */
  829. interface ShowdownOptionDescription {
  830. /**
  831. * The default value of option.
  832. */
  833. defaultValue?: boolean;
  834. /**
  835. * The description of the option.
  836. */
  837. description?: string;
  838. /**
  839. * The type of the option value.
  840. */
  841. type?: 'boolean' | 'string' | 'integer'
  842. }
  843. /**
  844. * Showdown options schema.
  845. */
  846. interface ShowdownOptionsSchema {
  847. [key: string]: ShowdownOptionDescription;
  848. }
  849. /**
  850. * Showdown subParser.
  851. */
  852. type SubParser = (...args: any[]) => string;
  853. /**
  854. * Showdown Converter prototype.
  855. *
  856. * @see https://github.com/showdownjs/showdown/blob/master/src/converter.js
  857. */
  858. interface Converter {
  859. /**
  860. * Listen to an event.
  861. *
  862. * @param name - The event name.
  863. * @param callback - The function that will be called when the event occurs.
  864. * @throws Throws if the type of `name` is not string.
  865. * @throws Throws if the type of `callback` is not function.
  866. * @example
  867. * ```ts
  868. * let converter: Converter = new Converter();
  869. * converter
  870. * .listen('hashBlock.before', (evtName, text, converter, options, globals) => {
  871. * // ... do stuff to text ...
  872. * return text;
  873. * })
  874. * .makeHtml('...');
  875. * ```
  876. */
  877. listen(name: string, callback: EventListener): Converter;
  878. /**
  879. * Converts a markdown string into HTML string.
  880. *
  881. * @param text - The input text (markdown).
  882. * @return The output HTML.
  883. */
  884. makeHtml(text: string): string;
  885. /**
  886. * Converts an HTML string into a markdown string.
  887. *
  888. * @param src - The input text (HTML)
  889. * @param [HTMLParser] A WHATWG DOM and HTML parser, such as JSDOM. If none is supplied, window.document will be used.
  890. * @returns The output markdown.
  891. */
  892. makeMarkdown(src: string, HTMLParser?: HTMLDocument): string;
  893. /**
  894. * Setting a "local" option only affects the specified Converter object.
  895. *
  896. * @param key - The key of the option.
  897. * @param value - The value of the option.
  898. */
  899. setOption(key: string, value: any): void;
  900. /**
  901. * Get the option of this Converter instance.
  902. *
  903. * @param key - The key of the option.
  904. * @returns Returns the value of the given `key`.
  905. */
  906. getOption(key: string): any;
  907. /**
  908. * Get the options of this Converter instance.
  909. *
  910. * @returns Returns the current convertor options object.
  911. */
  912. getOptions(): ShowdownOptions;
  913. /**
  914. * Add extension to THIS converter.
  915. *
  916. * @param extension - The new extension to add.
  917. * @param name - The extension name.
  918. */
  919. addExtension(extension: (() => ShowdownExtension[] | ShowdownExtension) | ShowdownExtension[] | ShowdownExtension, name?: string): void;
  920. /**
  921. * Use a global registered extension with THIS converter.
  922. *
  923. * @param extensionName - Name of the previously registered extension.
  924. */
  925. useExtension(extensionName: string): void;
  926. /**
  927. * Set a "local" flavor for THIS Converter instance.
  928. *
  929. * @param flavor - The flavor name.
  930. */
  931. setFlavor(name: Flavor): void;
  932. /**
  933. * Get the "local" currently set flavor of this converter.
  934. *
  935. * @returns Returns string flavor name.
  936. */
  937. getFlavor(): Flavor;
  938. /**
  939. * Remove an extension from THIS converter.
  940. *
  941. * @remarks This is a costly operation. It's better to initialize a new converter.
  942. * and specify the extensions you wish to use.
  943. * @param extensions - The extensions to remove.
  944. */
  945. removeExtension(extensions: ShowdownExtension[] | ShowdownExtension): void;
  946. /**
  947. * Get all extensions.
  948. *
  949. * @return all extensions.
  950. */
  951. getAllExtensions(): ConverterExtensions;
  952. /**
  953. * Get the metadata of the previously parsed document.
  954. *
  955. * @param raw - If to returns Row or Metadata.
  956. * @returns Returns Row if `row` is `true`, otherwise Metadata.
  957. */
  958. getMetadata(raw?: boolean): string | Metadata
  959. /**
  960. * Get the metadata format of the previously parsed document.
  961. *
  962. * @returns Returns the metadata format.
  963. */
  964. getMetadataFormat(): string;
  965. }
  966. interface ConverterStatic {
  967. /**
  968. * @constructor
  969. * @param converterOptions - Configuration object, describes which extensions to apply.
  970. */
  971. new(converterOptions?: ConverterOptions): Converter;
  972. }
  973. /**
  974. * Helper Interface
  975. */
  976. interface Helper {
  977. replaceRecursiveRegExp(...args: any[]): string;
  978. [key: string]: (...args: any[]) => any;
  979. }
  980. /**
  981. * Constructor function for a Converter.
  982. */
  983. var Converter: ConverterStatic;
  984. /**
  985. * Showdown helper.
  986. */
  987. var helper: Helper;
  988. /**
  989. * Showdown extensions.
  990. */
  991. var extensions: ShowdownExtensions;
  992. /**
  993. * Setting a "global" option affects all instances of showdown.
  994. *
  995. * @param key - the option key.
  996. * @param value - the option value.
  997. */
  998. function setOption(key: string, value: any): typeof Showdown;
  999. /**
  1000. * Get a "global" option.
  1001. *
  1002. * @param key - the option key.
  1003. * @returns Returns the value of the given `key`.
  1004. */
  1005. function getOption(key: string): any;
  1006. /**
  1007. * Get the "global" options.
  1008. *
  1009. * @returns Returns a options object.
  1010. */
  1011. function getOptions(): ShowdownOptions;
  1012. /**
  1013. * Reset "global" options to the default values.
  1014. */
  1015. function resetOptions(): void;
  1016. /**
  1017. * Setting a "global" flavor affects all instances of showdown.
  1018. *
  1019. * @param name - The flavor name.
  1020. */
  1021. function setFlavor(name: Flavor): void;
  1022. /**
  1023. * Get the "global" currently set flavor.
  1024. *
  1025. * @returns Returns string flavor name.
  1026. */
  1027. function getFlavor(): Flavor;
  1028. /**
  1029. * Get the options of a specified flavor. Returns undefined if the flavor was not found.
  1030. *
  1031. * @param name - Name of the flavor.
  1032. * @returns Returns options object of the given flavor `name`.
  1033. */
  1034. function getFlavorOptions(name: Flavor): ShowdownOptions | undefined;
  1035. /**
  1036. * Get the default options.
  1037. *
  1038. * @param [simple=true] - If to returns the default showdown options or the showdown options schema.
  1039. * @returns Returns the options schema if `simple` is `false`, otherwise the default showdown options.
  1040. */
  1041. function getDefaultOptions(simple?: boolean): ShowdownOptionsSchema | ShowdownOptions;
  1042. /**
  1043. * Get a registered subParser.
  1044. *
  1045. * @param name - The parser name.
  1046. * @returns Returns the parser of the given `name`.
  1047. * @throws Throws if `name` is not of type string.
  1048. * @throws Throws if the parser is not exists.
  1049. */
  1050. function subParser(name: string): SubParser;
  1051. /**
  1052. * Register a subParser.
  1053. *
  1054. * @param name - The name of the new parser.
  1055. * @param func - The handler function of the new parser.
  1056. * @throws Throws if `name` is not of type string.
  1057. */
  1058. function subParser(name: string, func: SubParser): void;
  1059. /**
  1060. * Get a registered extension.
  1061. *
  1062. * @param name - The extension name.
  1063. * @returns Returns the extension of the given `name`.
  1064. * @throws Throws if `name` is not of type string.
  1065. * @throws Throws if the extension is not exists.
  1066. */
  1067. function extension(name: string): ShowdownExtension[];
  1068. /**
  1069. * Register a extension.
  1070. *
  1071. * @param name - The name of the new extension.
  1072. * @param ext - The extension.
  1073. * @throws Throws if `name` is not of type string.
  1074. */
  1075. function extension(name: string, ext: (() => ShowdownExtension[] | ShowdownExtension) | ShowdownExtension[] | ShowdownExtension): void;
  1076. /**
  1077. * Get the "global" extensions.
  1078. *
  1079. * @return Returns all extensions.
  1080. */
  1081. function getAllExtensions(): ShowdownExtensions;
  1082. /**
  1083. * Remove an extension.
  1084. *
  1085. * @param name - The extension name.
  1086. */
  1087. function removeExtension(name: string): void;
  1088. /**
  1089. * Removes all extensions.
  1090. */
  1091. function resetExtensions(): void;
  1092. /**
  1093. * Checks if the given `ext` is a valid showdown extension.
  1094. *
  1095. * @param ext - The extension to checks.
  1096. * @returns Returns `true` if the extension is valid showdown extension, otherwise `false`.
  1097. */
  1098. function validateExtension(ext: ShowdownExtension[] | ShowdownExtension): boolean;
  1099. }