index.d.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. declare namespace render {
  2. type Options = {
  3. /**
  4. * Custom single tags (selfClosing).
  5. *
  6. * @default []
  7. */
  8. singleTags: string[] | RegExp[];
  9. /**
  10. * Closing format for single tag.
  11. *
  12. * Formats:
  13. *
  14. * tag: `<br></br>`, slash: `<br />`, default: `<br>`
  15. *
  16. */
  17. closingSingleTag: 'tag' | 'slash';
  18. /**
  19. * If all attributes should be quoted.
  20. * Otherwise attributes will be unquoted when allowed.
  21. *
  22. * @default true
  23. */
  24. quoteAllAttributes: boolean;
  25. /**
  26. * Quote style
  27. *
  28. * 0 - Smart quotes
  29. * <img src="https://example.com/example.png" onload='testFunc("test")'>
  30. * 1 - Single quotes
  31. * <img src='https://example.com/example.png' onload='testFunc("test")'>
  32. * 2 - double quotes
  33. * <img src="https://example.com/example.png" onload="testFunc("test")">
  34. *
  35. * @default 2
  36. */
  37. quoteStyle: 0 | 1 | 2
  38. };
  39. // PostHTML Tree
  40. type Tree = Node[];
  41. type Node = NodeText | NodeTag;
  42. type NodeText = string;
  43. type NodeTag = {
  44. tag: string;
  45. attrs?: Attributes;
  46. content?: Node[];
  47. };
  48. type Attributes = Record<string, string>;
  49. }
  50. /**
  51. * Render PostHTML Tree to HTML
  52. * @param tree PostHTML Tree
  53. * @param options Render options
  54. * @returns HTML
  55. */
  56. declare function render(
  57. tree: render.Tree,
  58. options?: Partial<render.Options>
  59. ): string;
  60. export = render;