dom-serializer
Advanced tools
Comparing version 1.4.1 to 2.0.0
@@ -5,100 +5,100 @@ "use strict"; | ||
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"], | ||
]); | ||
"altGlyph", | ||
"altGlyphDef", | ||
"altGlyphItem", | ||
"animateColor", | ||
"animateMotion", | ||
"animateTransform", | ||
"clipPath", | ||
"feBlend", | ||
"feColorMatrix", | ||
"feComponentTransfer", | ||
"feComposite", | ||
"feConvolveMatrix", | ||
"feDiffuseLighting", | ||
"feDisplacementMap", | ||
"feDistantLight", | ||
"feDropShadow", | ||
"feFlood", | ||
"feFuncA", | ||
"feFuncB", | ||
"feFuncG", | ||
"feFuncR", | ||
"feGaussianBlur", | ||
"feImage", | ||
"feMerge", | ||
"feMergeNode", | ||
"feMorphology", | ||
"feOffset", | ||
"fePointLight", | ||
"feSpecularLighting", | ||
"feSpotLight", | ||
"feTile", | ||
"feTurbulence", | ||
"foreignObject", | ||
"glyphRef", | ||
"linearGradient", | ||
"radialGradient", | ||
"textPath", | ||
].map(function (val) { return [val.toLowerCase(), val]; })); | ||
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"], | ||
]); | ||
"definitionURL", | ||
"attributeName", | ||
"attributeType", | ||
"baseFrequency", | ||
"baseProfile", | ||
"calcMode", | ||
"clipPathUnits", | ||
"diffuseConstant", | ||
"edgeMode", | ||
"filterUnits", | ||
"glyphRef", | ||
"gradientTransform", | ||
"gradientUnits", | ||
"kernelMatrix", | ||
"kernelUnitLength", | ||
"keyPoints", | ||
"keySplines", | ||
"keyTimes", | ||
"lengthAdjust", | ||
"limitingConeAngle", | ||
"markerHeight", | ||
"markerUnits", | ||
"markerWidth", | ||
"maskContentUnits", | ||
"maskUnits", | ||
"numOctaves", | ||
"pathLength", | ||
"patternContentUnits", | ||
"patternTransform", | ||
"patternUnits", | ||
"pointsAtX", | ||
"pointsAtY", | ||
"pointsAtZ", | ||
"preserveAlpha", | ||
"preserveAspectRatio", | ||
"primitiveUnits", | ||
"refX", | ||
"refY", | ||
"repeatCount", | ||
"repeatDur", | ||
"requiredExtensions", | ||
"requiredFeatures", | ||
"specularConstant", | ||
"specularExponent", | ||
"spreadMethod", | ||
"startOffset", | ||
"stdDeviation", | ||
"stitchTiles", | ||
"surfaceScale", | ||
"systemLanguage", | ||
"tableValues", | ||
"targetX", | ||
"targetY", | ||
"textLength", | ||
"viewBox", | ||
"viewTarget", | ||
"xChannelSelector", | ||
"yChannelSelector", | ||
"zoomAndPan", | ||
].map(function (val) { return [val.toLowerCase(), val]; })); |
@@ -1,2 +0,2 @@ | ||
import type { Node } from "domhandler"; | ||
import type { AnyNode } from "domhandler"; | ||
export interface DomSerializerOptions { | ||
@@ -28,4 +28,12 @@ /** | ||
/** | ||
* Encode characters that are either reserved in HTML or XML, or are outside of the ASCII range. | ||
* 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` | ||
*/ | ||
encodeEntities?: boolean | "utf8"; | ||
/** | ||
* Option inherited from parsing; will be used as the default value for `encodeEntities`. | ||
* | ||
* @default true | ||
@@ -43,3 +51,4 @@ */ | ||
*/ | ||
export default function render(node: Node | ArrayLike<Node>, options?: DomSerializerOptions): string; | ||
export declare function render(node: AnyNode | ArrayLike<AnyNode>, options?: DomSerializerOptions): string; | ||
export default render; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -15,3 +15,7 @@ "use strict"; | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -34,2 +38,3 @@ if (k2 === undefined) k2 = k; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.render = void 0; | ||
/* | ||
@@ -46,3 +51,3 @@ * Module dependencies | ||
*/ | ||
var foreignNames_1 = require("./foreignNames"); | ||
var foreignNames_js_1 = require("./foreignNames.js"); | ||
var unencodedElements = new Set([ | ||
@@ -58,2 +63,5 @@ "style", | ||
]); | ||
function replaceQuotes(value) { | ||
return value.replace(/"/g, """); | ||
} | ||
/** | ||
@@ -63,4 +71,10 @@ * Format attributes | ||
function formatAttributes(attributes, opts) { | ||
var _a; | ||
if (!attributes) | ||
return; | ||
var encode = ((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) === false | ||
? replaceQuotes | ||
: opts.xmlMode || opts.encodeEntities !== "utf8" | ||
? entities_1.encodeXML | ||
: entities_1.escapeAttribute; | ||
return Object.keys(attributes) | ||
@@ -72,3 +86,3 @@ .map(function (key) { | ||
/* Fix up mixed-case attribute names */ | ||
key = (_b = foreignNames_1.attributeNames.get(key)) !== null && _b !== void 0 ? _b : key; | ||
key = (_b = foreignNames_js_1.attributeNames.get(key)) !== null && _b !== void 0 ? _b : key; | ||
} | ||
@@ -78,5 +92,3 @@ if (!opts.emptyAttrs && !opts.xmlMode && value === "") { | ||
} | ||
return key + "=\"" + (opts.decodeEntities !== false | ||
? entities_1.encodeXML(value) | ||
: value.replace(/"/g, """)) + "\""; | ||
return "".concat(key, "=\"").concat(encode(value), "\""); | ||
}) | ||
@@ -126,2 +138,3 @@ .join(" "); | ||
} | ||
exports.render = render; | ||
exports.default = render; | ||
@@ -132,4 +145,5 @@ function renderNode(node, options) { | ||
return render(node.children, options); | ||
// @ts-expect-error We don't use `Doctype` yet | ||
case ElementType.Doctype: | ||
case ElementType.Directive: | ||
case ElementType.Doctype: | ||
return renderDirective(node); | ||
@@ -165,3 +179,3 @@ case ElementType.Comment: | ||
/* Fix up mixed-case element names */ | ||
elem.name = (_a = foreignNames_1.elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name; | ||
elem.name = (_a = foreignNames_js_1.elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name; | ||
/* Exit foreign mode at integration points */ | ||
@@ -176,6 +190,6 @@ if (elem.parent && | ||
} | ||
var tag = "<" + elem.name; | ||
var tag = "<".concat(elem.name); | ||
var attribs = formatAttributes(elem.attribs, opts); | ||
if (attribs) { | ||
tag += " " + attribs; | ||
tag += " ".concat(attribs); | ||
} | ||
@@ -198,3 +212,3 @@ if (elem.children.length === 0 && | ||
if (opts.xmlMode || !singleTag.has(elem.name)) { | ||
tag += "</" + elem.name + ">"; | ||
tag += "</".concat(elem.name, ">"); | ||
} | ||
@@ -205,12 +219,16 @@ } | ||
function renderDirective(elem) { | ||
return "<" + elem.data + ">"; | ||
return "<".concat(elem.data, ">"); | ||
} | ||
function renderText(elem, opts) { | ||
var _a; | ||
var data = elem.data || ""; | ||
// If entities weren't decoded, no need to encode them back | ||
if (opts.decodeEntities !== false && | ||
if (((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) !== false && | ||
!(!opts.xmlMode && | ||
elem.parent && | ||
unencodedElements.has(elem.parent.name))) { | ||
data = entities_1.encodeXML(data); | ||
data = | ||
opts.xmlMode || opts.encodeEntities !== "utf8" | ||
? (0, entities_1.encodeXML)(data) | ||
: (0, entities_1.escapeText)(data); | ||
} | ||
@@ -220,6 +238,6 @@ return data; | ||
function renderCdata(elem) { | ||
return "<![CDATA[" + elem.children[0].data + "]]>"; | ||
return "<![CDATA[".concat(elem.children[0].data, "]]>"); | ||
} | ||
function renderComment(elem) { | ||
return "<!--" + elem.data + "-->"; | ||
return "<!--".concat(elem.data, "-->"); | ||
} |
{ | ||
"name": "dom-serializer", | ||
"version": "1.4.1", | ||
"version": "2.0.0", | ||
"description": "render domhandler DOM nodes to a string", | ||
@@ -14,6 +14,11 @@ "author": "Felix Boehm <me@feedic.com>", | ||
"type": "git", | ||
"url": "git://github.com/cheeriojs/dom-renderer.git" | ||
"url": "git://github.com/cheeriojs/dom-serializer.git" | ||
}, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"module": "lib/esm/index.js", | ||
"exports": { | ||
"require": "./lib/index.js", | ||
"import": "./lib/esm/index.js" | ||
}, | ||
"files": [ | ||
@@ -23,27 +28,33 @@ "lib/**/*" | ||
"dependencies": { | ||
"domelementtype": "^2.0.1", | ||
"domhandler": "^4.2.0", | ||
"entities": "^2.0.0" | ||
"domelementtype": "^2.3.0", | ||
"domhandler": "^5.0.2", | ||
"entities": "^4.2.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", | ||
"@types/jest": "^27.4.1", | ||
"@types/node": "^17.0.23", | ||
"@typescript-eslint/eslint-plugin": "^5.18.0", | ||
"@typescript-eslint/parser": "^5.18.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" | ||
"eslint": "^8.12.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"htmlparser2": "^7.2.0", | ||
"jest": "^27.5.1", | ||
"prettier": "^2.6.2", | ||
"ts-jest": "^27.1.4", | ||
"typescript": "^4.6.3" | ||
}, | ||
"scripts": { | ||
"test": "jest --coverage && npm run lint", | ||
"coverage": "cat coverage/lcov.info | coveralls", | ||
"lint": "eslint src", | ||
"format": "prettier --write '**/*.{ts,md,json}'", | ||
"build": "tsc", | ||
"test": "npm run test:jest && npm run lint", | ||
"test:jest": "jest", | ||
"lint": "npm run lint:es && npm run lint:prettier", | ||
"lint:es": "eslint --ignore-path .gitignore .", | ||
"lint:prettier": "npm run prettier -- --check", | ||
"format": "npm run format:es && npm run format:prettier", | ||
"format:es": "npm run lint:es -- --fix", | ||
"format:prettier": "npm run prettier -- --write", | ||
"prettier": "prettier \"**/*.{ts,md,json,yml}\" --ignore-path .gitignore", | ||
"build": "npm run build:cjs && npm run build:esm", | ||
"build:cjs": "tsc", | ||
"build:esm": "tsc --module esnext --target es2019 --outDir lib/esm && echo '{\"type\":\"module\"}' > lib/esm/package.json", | ||
"prepare": "npm run build" | ||
@@ -53,3 +64,6 @@ }, | ||
"preset": "ts-jest", | ||
"testEnvironment": "node" | ||
"testEnvironment": "node", | ||
"moduleNameMapper": { | ||
"^(.*)\\.js$": "$1" | ||
} | ||
}, | ||
@@ -56,0 +70,0 @@ "funding": "https://github.com/cheeriojs/dom-serializer?sponsor=1", |
@@ -34,2 +34,14 @@ # dom-serializer [![Build Status](https://travis-ci.com/cheeriojs/dom-serializer.svg?branch=master)](https://travis-ci.com/cheeriojs/dom-serializer) | ||
### `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` | ||
@@ -39,3 +51,3 @@ | ||
Encode characters that are either reserved in HTML or XML, or are outside of the ASCII range. | ||
Option inherited from parsing; will be used as the default value for `encodeEntities`. | ||
@@ -42,0 +54,0 @@ **`default`** true |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28813
12
728
110
+ Addeddomhandler@5.0.3(transitive)
+ Addedentities@4.5.0(transitive)
- Removeddomhandler@4.3.1(transitive)
- Removedentities@2.2.0(transitive)
Updateddomelementtype@^2.3.0
Updateddomhandler@^5.0.2
Updatedentities@^4.2.0