You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.1 KiB

3 months ago
  1. # dom-serializer [![Build Status](https://travis-ci.com/cheeriojs/dom-serializer.svg?branch=master)](https://travis-ci.com/cheeriojs/dom-serializer)
  2. Renders a [domhandler](https://github.com/fb55/domhandler) DOM node or an array of domhandler DOM nodes to a string.
  3. ```js
  4. import render from "dom-serializer";
  5. // OR
  6. const render = require("dom-serializer").default;
  7. ```
  8. # API
  9. ## `render`
  10. **render**(`node`: Node \| Node[], `options?`: [_Options_](#Options)): _string_
  11. Renders a DOM node or an array of DOM nodes to a string.
  12. Can be thought of as the equivalent of the `outerHTML` of the passed node(s).
  13. #### Parameters:
  14. | Name | Type | Default value | Description |
  15. | :-------- | :--------------------------------- | :------------ | :----------------------------- |
  16. | `node` | Node \| Node[] | - | Node to be rendered. |
  17. | `options` | [_DomSerializerOptions_](#Options) | {} | Changes serialization behavior |
  18. **Returns:** _string_
  19. ## Options
  20. ### `decodeEntities`
  21. `Optional` **decodeEntities**: _boolean_
  22. Encode characters that are either reserved in HTML or XML, or are outside of the ASCII range.
  23. **`default`** true
  24. ---
  25. ### `emptyAttrs`
  26. `Optional` **emptyAttrs**: _boolean_
  27. Print an empty attribute's value.
  28. **`default`** xmlMode
  29. **`example`** With <code>emptyAttrs: false</code>: <code>&lt;input checked&gt;</code>
  30. **`example`** With <code>emptyAttrs: true</code>: <code>&lt;input checked=""&gt;</code>
  31. ---
  32. ### `selfClosingTags`
  33. `Optional` **selfClosingTags**: _boolean_
  34. Print self-closing tags for tags without contents.
  35. **`default`** xmlMode
  36. **`example`** With <code>selfClosingTags: false</code>: <code>&lt;foo&gt;&lt;/foo&gt;</code>
  37. **`example`** With <code>selfClosingTags: true</code>: <code>&lt;foo /&gt;</code>
  38. ---
  39. ### `xmlMode`
  40. `Optional` **xmlMode**: _boolean_ \| _"foreign"_
  41. Treat the input as an XML document; enables the `emptyAttrs` and `selfClosingTags` options.
  42. If the value is `"foreign"`, it will try to correct mixed-case attribute names.
  43. **`default`** false
  44. ---
  45. ## Ecosystem
  46. | Name | Description |
  47. | ------------------------------------------------------------- | ------------------------------------------------------- |
  48. | [htmlparser2](https://github.com/fb55/htmlparser2) | Fast & forgiving HTML/XML parser |
  49. | [domhandler](https://github.com/fb55/domhandler) | Handler for htmlparser2 that turns documents into a DOM |
  50. | [domutils](https://github.com/fb55/domutils) | Utilities for working with domhandler's DOM |
  51. | [css-select](https://github.com/fb55/css-select) | CSS selector engine, compatible with domhandler's DOM |
  52. | [cheerio](https://github.com/cheeriojs/cheerio) | The jQuery API for domhandler's DOM |
  53. | [dom-serializer](https://github.com/cheeriojs/dom-serializer) | Serializer for domhandler's DOM |
  54. ---
  55. LICENSE: MIT