diff options
Diffstat (limited to 'node_modules/dom-serializer')
-rw-r--r-- | node_modules/dom-serializer/LICENSE | 11 | ||||
-rw-r--r-- | node_modules/dom-serializer/README.md | 97 | ||||
-rw-r--r-- | node_modules/dom-serializer/lib/foreignNames.d.ts | 3 | ||||
-rw-r--r-- | node_modules/dom-serializer/lib/foreignNames.d.ts.map | 1 | ||||
-rw-r--r-- | node_modules/dom-serializer/lib/foreignNames.js | 103 | ||||
-rw-r--r-- | node_modules/dom-serializer/lib/index.d.ts | 43 | ||||
-rw-r--r-- | node_modules/dom-serializer/lib/index.d.ts.map | 1 | ||||
-rw-r--r-- | node_modules/dom-serializer/lib/index.js | 211 | ||||
-rw-r--r-- | node_modules/dom-serializer/package.json | 55 |
9 files changed, 525 insertions, 0 deletions
diff --git a/node_modules/dom-serializer/LICENSE b/node_modules/dom-serializer/LICENSE new file mode 100644 index 0000000..3d241a8 --- /dev/null +++ b/node_modules/dom-serializer/LICENSE @@ -0,0 +1,11 @@ +License + +(The MIT License) + +Copyright (c) 2014 The cheeriojs contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/dom-serializer/README.md b/node_modules/dom-serializer/README.md new file mode 100644 index 0000000..9ef0eec --- /dev/null +++ b/node_modules/dom-serializer/README.md @@ -0,0 +1,97 @@ +# dom-serializer [![Build Status](https://travis-ci.com/cheeriojs/dom-serializer.svg?branch=master)](https://travis-ci.com/cheeriojs/dom-serializer) + +Renders a [domhandler](https://github.com/fb55/domhandler) DOM node or an array of domhandler DOM nodes to a string. + +```js +import render from "dom-serializer"; + +// OR + +const render = require("dom-serializer").default; +``` + +# API + +## `render` + +▸ **render**(`node`: Node \| Node[], `options?`: [_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: + +| Name | Type | Default value | Description | +| :-------- | :--------------------------------- | :------------ | :----------------------------- | +| `node` | Node \| Node[] | - | Node to be rendered. | +| `options` | [_DomSerializerOptions_](#Options) | {} | Changes serialization behavior | + +**Returns:** _string_ + +## Options + +### `decodeEntities` + +• `Optional` **decodeEntities**: _boolean_ + +Encode characters that are either reserved in HTML or XML, or are outside of the ASCII range. + +**`default`** true + +--- + +### `emptyAttrs` + +• `Optional` **emptyAttrs**: _boolean_ + +Print an empty attribute's value. + +**`default`** xmlMode + +**`example`** With <code>emptyAttrs: false</code>: <code><input checked></code> + +**`example`** With <code>emptyAttrs: true</code>: <code><input checked=""></code> + +--- + +### `selfClosingTags` + +• `Optional` **selfClosingTags**: _boolean_ + +Print self-closing tags for tags without contents. + +**`default`** xmlMode + +**`example`** With <code>selfClosingTags: false</code>: <code><foo></foo></code> + +**`example`** With <code>selfClosingTags: true</code>: <code><foo /></code> + +--- + +### `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 + +| Name | Description | +| ------------------------------------------------------------- | ------------------------------------------------------- | +| [htmlparser2](https://github.com/fb55/htmlparser2) | Fast & forgiving HTML/XML parser | +| [domhandler](https://github.com/fb55/domhandler) | Handler for htmlparser2 that turns documents into a DOM | +| [domutils](https://github.com/fb55/domutils) | Utilities for working with domhandler's DOM | +| [css-select](https://github.com/fb55/css-select) | CSS selector engine, compatible with domhandler's DOM | +| [cheerio](https://github.com/cheeriojs/cheerio) | The jQuery API for domhandler's DOM | +| [dom-serializer](https://github.com/cheeriojs/dom-serializer) | Serializer for domhandler's DOM | + +--- + +LICENSE: MIT diff --git a/node_modules/dom-serializer/lib/foreignNames.d.ts b/node_modules/dom-serializer/lib/foreignNames.d.ts new file mode 100644 index 0000000..a8b0938 --- /dev/null +++ b/node_modules/dom-serializer/lib/foreignNames.d.ts @@ -0,0 +1,3 @@ +export declare const elementNames: Map<string, string>; +export declare const attributeNames: Map<string, string>; +//# sourceMappingURL=foreignNames.d.ts.map
\ No newline at end of file diff --git a/node_modules/dom-serializer/lib/foreignNames.d.ts.map b/node_modules/dom-serializer/lib/foreignNames.d.ts.map new file mode 100644 index 0000000..50e4f26 --- /dev/null +++ b/node_modules/dom-serializer/lib/foreignNames.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"foreignNames.d.ts","sourceRoot":"","sources":["../src/foreignNames.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,qBAsCvB,CAAC;AACH,eAAO,MAAM,cAAc,qBA4DzB,CAAC"}
\ No newline at end of file diff --git a/node_modules/dom-serializer/lib/foreignNames.js b/node_modules/dom-serializer/lib/foreignNames.js new file mode 100644 index 0000000..966253e --- /dev/null +++ b/node_modules/dom-serializer/lib/foreignNames.js @@ -0,0 +1,103 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.attributeNames = exports.elementNames = void 0; +exports.elementNames = new Map([ + ["altglyph", "altGlyph"], + ["altglyphdef", "altGlyphDef"], + ["altglyphitem", "altGlyphItem"], + ["animatecolor", "animateColor"], + ["animatemotion", "animateMotion"], + ["animatetransform", "animateTransform"], + ["clippath", "clipPath"], + ["feblend", "feBlend"], + ["fecolormatrix", "feColorMatrix"], + ["fecomponenttransfer", "feComponentTransfer"], + ["fecomposite", "feComposite"], + ["feconvolvematrix", "feConvolveMatrix"], + ["fediffuselighting", "feDiffuseLighting"], + ["fedisplacementmap", "feDisplacementMap"], + ["fedistantlight", "feDistantLight"], + ["fedropshadow", "feDropShadow"], + ["feflood", "feFlood"], + ["fefunca", "feFuncA"], + ["fefuncb", "feFuncB"], + ["fefuncg", "feFuncG"], + ["fefuncr", "feFuncR"], + ["fegaussianblur", "feGaussianBlur"], + ["feimage", "feImage"], + ["femerge", "feMerge"], + ["femergenode", "feMergeNode"], + ["femorphology", "feMorphology"], + ["feoffset", "feOffset"], + ["fepointlight", "fePointLight"], + ["fespecularlighting", "feSpecularLighting"], + ["fespotlight", "feSpotLight"], + ["fetile", "feTile"], + ["feturbulence", "feTurbulence"], + ["foreignobject", "foreignObject"], + ["glyphref", "glyphRef"], + ["lineargradient", "linearGradient"], + ["radialgradient", "radialGradient"], + ["textpath", "textPath"], +]); +exports.attributeNames = new Map([ + ["definitionurl", "definitionURL"], + ["attributename", "attributeName"], + ["attributetype", "attributeType"], + ["basefrequency", "baseFrequency"], + ["baseprofile", "baseProfile"], + ["calcmode", "calcMode"], + ["clippathunits", "clipPathUnits"], + ["diffuseconstant", "diffuseConstant"], + ["edgemode", "edgeMode"], + ["filterunits", "filterUnits"], + ["glyphref", "glyphRef"], + ["gradienttransform", "gradientTransform"], + ["gradientunits", "gradientUnits"], + ["kernelmatrix", "kernelMatrix"], + ["kernelunitlength", "kernelUnitLength"], + ["keypoints", "keyPoints"], + ["keysplines", "keySplines"], + ["keytimes", "keyTimes"], + ["lengthadjust", "lengthAdjust"], + ["limitingconeangle", "limitingConeAngle"], + ["markerheight", "markerHeight"], + ["markerunits", "markerUnits"], + ["markerwidth", "markerWidth"], + ["maskcontentunits", "maskContentUnits"], + ["maskunits", "maskUnits"], + ["numoctaves", "numOctaves"], + ["pathlength", "pathLength"], + ["patterncontentunits", "patternContentUnits"], + ["patterntransform", "patternTransform"], + ["patternunits", "patternUnits"], + ["pointsatx", "pointsAtX"], + ["pointsaty", "pointsAtY"], + ["pointsatz", "pointsAtZ"], + ["preservealpha", "preserveAlpha"], + ["preserveaspectratio", "preserveAspectRatio"], + ["primitiveunits", "primitiveUnits"], + ["refx", "refX"], + ["refy", "refY"], + ["repeatcount", "repeatCount"], + ["repeatdur", "repeatDur"], + ["requiredextensions", "requiredExtensions"], + ["requiredfeatures", "requiredFeatures"], + ["specularconstant", "specularConstant"], + ["specularexponent", "specularExponent"], + ["spreadmethod", "spreadMethod"], + ["startoffset", "startOffset"], + ["stddeviation", "stdDeviation"], + ["stitchtiles", "stitchTiles"], + ["surfacescale", "surfaceScale"], + ["systemlanguage", "systemLanguage"], + ["tablevalues", "tableValues"], + ["targetx", "targetX"], + ["targety", "targetY"], + ["textlength", "textLength"], + ["viewbox", "viewBox"], + ["viewtarget", "viewTarget"], + ["xchannelselector", "xChannelSelector"], + ["ychannelselector", "yChannelSelector"], + ["zoomandpan", "zoomAndPan"], +]); diff --git a/node_modules/dom-serializer/lib/index.d.ts b/node_modules/dom-serializer/lib/index.d.ts new file mode 100644 index 0000000..84f6d16 --- /dev/null +++ b/node_modules/dom-serializer/lib/index.d.ts @@ -0,0 +1,43 @@ +import type { Node } from "domhandler"; +export interface DomSerializerOptions { + /** + * Print an empty attribute's value. + * + * @default xmlMode + * @example With <code>emptyAttrs: false</code>: <code><input checked></code> + * @example With <code>emptyAttrs: true</code>: <code><input checked=""></code> + */ + emptyAttrs?: boolean; + /** + * Print self-closing tags for tags without contents. + * + * @default xmlMode + * @example With <code>selfClosingTags: false</code>: <code><foo></foo></code> + * @example With <code>selfClosingTags: true</code>: <code><foo /></code> + */ + selfClosingTags?: boolean; + /** + * 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 + */ + xmlMode?: boolean | "foreign"; + /** + * Encode characters that are either reserved in HTML or XML, or are outside of the ASCII range. + * + * @default true + */ + decodeEntities?: boolean; +} +/** + * 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). + * + * @param node Node to be rendered. + * @param options Changes serialization behavior + */ +export default function render(node: Node | ArrayLike<Node>, options?: DomSerializerOptions): string; +//# sourceMappingURL=index.d.ts.map
\ No newline at end of file diff --git a/node_modules/dom-serializer/lib/index.d.ts.map b/node_modules/dom-serializer/lib/index.d.ts.map new file mode 100644 index 0000000..c04bdd4 --- /dev/null +++ b/node_modules/dom-serializer/lib/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAuC,MAAM,YAAY,CAAC;AAW5E,MAAM,WAAW,oBAAoB;IACnC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAqED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAC5B,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,EAC5B,OAAO,GAAE,oBAAyB,GACjC,MAAM,CAUR"}
\ No newline at end of file diff --git a/node_modules/dom-serializer/lib/index.js b/node_modules/dom-serializer/lib/index.js new file mode 100644 index 0000000..a5e1f93 --- /dev/null +++ b/node_modules/dom-serializer/lib/index.js @@ -0,0 +1,211 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/* + * Module dependencies + */ +var ElementType = __importStar(require("domelementtype")); +var entities_1 = require("entities"); +/** + * Mixed-case SVG and MathML tags & attributes + * recognized by the HTML parser. + * + * @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign + */ +var foreignNames_1 = require("./foreignNames"); +var unencodedElements = new Set([ + "style", + "script", + "xmp", + "iframe", + "noembed", + "noframes", + "plaintext", + "noscript", +]); +/** + * Format attributes + */ +function formatAttributes(attributes, opts) { + if (!attributes) + return; + return Object.keys(attributes) + .map(function (key) { + var _a, _b; + var value = (_a = attributes[key]) !== null && _a !== void 0 ? _a : ""; + if (opts.xmlMode === "foreign") { + /* Fix up mixed-case attribute names */ + key = (_b = foreignNames_1.attributeNames.get(key)) !== null && _b !== void 0 ? _b : key; + } + if (!opts.emptyAttrs && !opts.xmlMode && value === "") { + return key; + } + return key + "=\"" + (opts.decodeEntities !== false + ? entities_1.encodeXML(value) + : value.replace(/"/g, """)) + "\""; + }) + .join(" "); +} +/** + * Self-enclosing tags + */ +var singleTag = new Set([ + "area", + "base", + "basefont", + "br", + "col", + "command", + "embed", + "frame", + "hr", + "img", + "input", + "isindex", + "keygen", + "link", + "meta", + "param", + "source", + "track", + "wbr", +]); +/** + * 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). + * + * @param node Node to be rendered. + * @param options Changes serialization behavior + */ +function render(node, options) { + if (options === void 0) { options = {}; } + var nodes = "length" in node ? node : [node]; + var output = ""; + for (var i = 0; i < nodes.length; i++) { + output += renderNode(nodes[i], options); + } + return output; +} +exports.default = render; +function renderNode(node, options) { + switch (node.type) { + case ElementType.Root: + return render(node.children, options); + case ElementType.Directive: + case ElementType.Doctype: + return renderDirective(node); + case ElementType.Comment: + return renderComment(node); + case ElementType.CDATA: + return renderCdata(node); + case ElementType.Script: + case ElementType.Style: + case ElementType.Tag: + return renderTag(node, options); + case ElementType.Text: + return renderText(node, options); + } +} +var foreignModeIntegrationPoints = new Set([ + "mi", + "mo", + "mn", + "ms", + "mtext", + "annotation-xml", + "foreignObject", + "desc", + "title", +]); +var foreignElements = new Set(["svg", "math"]); +function renderTag(elem, opts) { + var _a; + // Handle SVG / MathML in HTML + if (opts.xmlMode === "foreign") { + /* Fix up mixed-case element names */ + elem.name = (_a = foreignNames_1.elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name; + /* Exit foreign mode at integration points */ + if (elem.parent && + foreignModeIntegrationPoints.has(elem.parent.name)) { + opts = __assign(__assign({}, opts), { xmlMode: false }); + } + } + if (!opts.xmlMode && foreignElements.has(elem.name)) { + opts = __assign(__assign({}, opts), { xmlMode: "foreign" }); + } + var tag = "<" + elem.name; + var attribs = formatAttributes(elem.attribs, opts); + if (attribs) { + tag += " " + attribs; + } + if (elem.children.length === 0 && + (opts.xmlMode + ? // In XML mode or foreign mode, and user hasn't explicitly turned off self-closing tags + opts.selfClosingTags !== false + : // User explicitly asked for self-closing tags, even in HTML mode + opts.selfClosingTags && singleTag.has(elem.name))) { + if (!opts.xmlMode) + tag += " "; + tag += "/>"; + } + else { + tag += ">"; + if (elem.children.length > 0) { + tag += render(elem.children, opts); + } + if (opts.xmlMode || !singleTag.has(elem.name)) { + tag += "</" + elem.name + ">"; + } + } + return tag; +} +function renderDirective(elem) { + return "<" + elem.data + ">"; +} +function renderText(elem, opts) { + var data = elem.data || ""; + // If entities weren't decoded, no need to encode them back + if (opts.decodeEntities !== false && + !(!opts.xmlMode && + elem.parent && + unencodedElements.has(elem.parent.name))) { + data = entities_1.encodeXML(data); + } + return data; +} +function renderCdata(elem) { + return "<![CDATA[" + elem.children[0].data + "]]>"; +} +function renderComment(elem) { + return "<!--" + elem.data + "-->"; +} diff --git a/node_modules/dom-serializer/package.json b/node_modules/dom-serializer/package.json new file mode 100644 index 0000000..942931e --- /dev/null +++ b/node_modules/dom-serializer/package.json @@ -0,0 +1,55 @@ +{ + "name": "dom-serializer", + "version": "1.3.2", + "description": "render domhandler DOM nodes to a string", + "author": "Felix Boehm <me@feedic.com>", + "sideEffects": false, + "keywords": [ + "html", + "xml", + "render" + ], + "repository": { + "type": "git", + "url": "git://github.com/cheeriojs/dom-renderer.git" + }, + "main": "lib/index.js", + "types": "lib/index.d.ts", + "files": [ + "lib/**/*" + ], + "dependencies": { + "domelementtype": "^2.0.1", + "domhandler": "^4.2.0", + "entities": "^2.0.0" + }, + "devDependencies": { + "@types/jest": "^26.0.23", + "@types/node": "^15.3.0", + "@typescript-eslint/eslint-plugin": "^4.23.0", + "@typescript-eslint/parser": "^4.23.0", + "cheerio": "^1.0.0-rc.9", + "coveralls": "^3.0.5", + "eslint": "^7.26.0", + "eslint-config-prettier": "^8.3.0", + "htmlparser2": "^6.1.0", + "jest": "^26.0.1", + "prettier": "^2.3.0", + "ts-jest": "^26.5.6", + "typescript": "^4.0.2" + }, + "scripts": { + "test": "jest --coverage && npm run lint", + "coverage": "cat coverage/lcov.info | coveralls", + "lint": "eslint src", + "format": "prettier --write '**/*.{ts,md,json}'", + "build": "tsc", + "prepare": "npm run build" + }, + "jest": { + "preset": "ts-jest", + "testEnvironment": "node" + }, + "funding": "https://github.com/cheeriojs/dom-serializer?sponsor=1", + "license": "MIT" +} |