Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

dom-serializer

Package Overview
Dependencies
3
Maintainers
3
Versions
17
Issues
File Explorer

Advanced tools

dom-serializer

render domhandler DOM nodes to a string

    2.0.0latest

Version published
Maintainers
3
Weekly downloads
26,901,030
decreased by-10.83%

Weekly downloads

Changelog

Source

Features

  • Added a encodeEntities option with utf8 output (#685) c9abf30
  • Added an ESM build (#684) 5426af3

Other changes

  • Bump domhandler to 5.0.2, entities to 4.2.0 b0b31ab
  • Added a regression test for XSS via missing attribute escaping (#441) dc550c2
  • Switched to GitHub Actions bc838d5 414af03 96448fc
  • Compute foreign name keys a956f87

New Contributors

  • @tosmolka made their first contribution in https://github.com/cheeriojs/dom-serializer/pull/441
  • @alloystory made their first contribution in https://github.com/cheeriojs/dom-serializer/pull/427

Full Changelog: https://github.com/cheeriojs/dom-serializer/compare/v1.3.2...v2.0.0

Readme

Source

dom-serializer Build Status

Renders a domhandler DOM node or an array of domhandler DOM nodes to a string.

import render from "dom-serializer"; // OR const render = require("dom-serializer").default;

API

render

render(node: Node | Node[], options?: Options): string

Renders a DOM node or an array of DOM nodes to a string.

Can be thought of as the equivalent of the outerHTML of the passed node(s).

Parameters:
NameTypeDefault valueDescription
nodeNode | Node[]-Node to be rendered.
optionsDomSerializerOptions{}Changes serialization behavior

Returns: string

Options

encodeEntities

Optional decodeEntities: boolean | "utf8"

Encode characters that are either reserved in HTML or XML.

If xmlMode is true or the value not 'utf8', characters outside of the utf8 range will be encoded as well.

default decodeEntities


decodeEntities

Optional decodeEntities: boolean

Option inherited from parsing; will be used as the default value for encodeEntities.

default true


emptyAttrs

Optional emptyAttrs: boolean

Print an empty attribute's value.

default xmlMode

example With emptyAttrs: false: <input checked>

example With emptyAttrs: true: <input checked="">


selfClosingTags

Optional selfClosingTags: boolean

Print self-closing tags for tags without contents.

default xmlMode

example With selfClosingTags: false: <foo></foo>

example With selfClosingTags: true: <foo />


xmlMode

Optional xmlMode: boolean | "foreign"

Treat the input as an XML document; enables the emptyAttrs and selfClosingTags options.

If the value is "foreign", it will try to correct mixed-case attribute names.

default false


Ecosystem

NameDescription
htmlparser2Fast & forgiving HTML/XML parser
domhandlerHandler for htmlparser2 that turns documents into a DOM
domutilsUtilities for working with domhandler's DOM
css-selectCSS selector engine, compatible with domhandler's DOM
cheerioThe jQuery API for domhandler's DOM
dom-serializerSerializer for domhandler's DOM

LICENSE: MIT

Keywords

FAQs

What is dom-serializer?

render domhandler DOM nodes to a string

Is dom-serializer popular?

The npm package dom-serializer receives a total of 20,650,797 weekly downloads. As such, dom-serializer popularity was classified as popular.

Is dom-serializer well maintained?

We found that dom-serializer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 3 open source maintainers collaborating on the project.

Last updated on 09 Apr 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc