html-react-parser 2.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/dist/html-react-parser.js +318 -299
- package/dist/html-react-parser.js.map +1 -1
- package/dist/html-react-parser.min.js +1 -1
- package/dist/html-react-parser.min.js.map +1 -1
- package/package.json +16 -16
|
@@ -1548,8 +1548,9 @@
|
|
|
1548
1548
|
var HEAD = 'head';
|
|
1549
1549
|
var BODY = 'body';
|
|
1550
1550
|
var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
|
|
1551
|
-
|
|
1552
|
-
var
|
|
1551
|
+
// match-all-characters in case of newlines (DOTALL)
|
|
1552
|
+
var HEAD_TAG_REGEX = /<head[^]*>/i;
|
|
1553
|
+
var BODY_TAG_REGEX = /<body[^]*>/i;
|
|
1553
1554
|
|
|
1554
1555
|
// falls back to `parseFromString` if `createHTMLDocument` cannot be used
|
|
1555
1556
|
var parseFromDocument = function () {
|
|
@@ -1608,7 +1609,8 @@
|
|
|
1608
1609
|
*/
|
|
1609
1610
|
parseFromDocument = function (html, tagName) {
|
|
1610
1611
|
if (tagName) {
|
|
1611
|
-
doc.documentElement.
|
|
1612
|
+
var element = doc.documentElement.querySelector(tagName);
|
|
1613
|
+
element.innerHTML = html;
|
|
1612
1614
|
return doc;
|
|
1613
1615
|
}
|
|
1614
1616
|
|
|
@@ -1663,24 +1665,25 @@
|
|
|
1663
1665
|
// the created document may come with filler head/body elements,
|
|
1664
1666
|
// so make sure to remove them if they don't actually exist
|
|
1665
1667
|
if (!HEAD_TAG_REGEX.test(html)) {
|
|
1666
|
-
element = doc.
|
|
1668
|
+
element = doc.querySelector(HEAD);
|
|
1667
1669
|
if (element) {
|
|
1668
1670
|
element.parentNode.removeChild(element);
|
|
1669
1671
|
}
|
|
1670
1672
|
}
|
|
1671
1673
|
|
|
1672
1674
|
if (!BODY_TAG_REGEX.test(html)) {
|
|
1673
|
-
element = doc.
|
|
1675
|
+
element = doc.querySelector(BODY);
|
|
1674
1676
|
if (element) {
|
|
1675
1677
|
element.parentNode.removeChild(element);
|
|
1676
1678
|
}
|
|
1677
1679
|
}
|
|
1678
1680
|
|
|
1679
|
-
return doc.
|
|
1681
|
+
return doc.querySelectorAll(HTML);
|
|
1680
1682
|
|
|
1681
1683
|
case HEAD:
|
|
1682
1684
|
case BODY:
|
|
1683
|
-
|
|
1685
|
+
doc = parseFromDocument(html);
|
|
1686
|
+
elements = doc.querySelectorAll(firstTagName);
|
|
1684
1687
|
|
|
1685
1688
|
// if there's a sibling element, then return both elements
|
|
1686
1689
|
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
|
|
@@ -1693,66 +1696,23 @@
|
|
|
1693
1696
|
if (parseFromTemplate) {
|
|
1694
1697
|
return parseFromTemplate(html);
|
|
1695
1698
|
}
|
|
1696
|
-
|
|
1697
|
-
return
|
|
1698
|
-
.childNodes;
|
|
1699
|
+
element = parseFromDocument(html, BODY).querySelector(BODY);
|
|
1700
|
+
return element.childNodes;
|
|
1699
1701
|
}
|
|
1700
1702
|
}
|
|
1701
1703
|
|
|
1702
1704
|
var domparser_1 = domparser$1;
|
|
1703
1705
|
|
|
1704
|
-
|
|
1705
|
-
* SVG elements are case-sensitive.
|
|
1706
|
-
*
|
|
1707
|
-
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#SVG_elements_A_to_Z}
|
|
1708
|
-
*/
|
|
1709
|
-
|
|
1710
|
-
var CASE_SENSITIVE_TAG_NAMES$1 = [
|
|
1711
|
-
'animateMotion',
|
|
1712
|
-
'animateTransform',
|
|
1713
|
-
'clipPath',
|
|
1714
|
-
'feBlend',
|
|
1715
|
-
'feColorMatrix',
|
|
1716
|
-
'feComponentTransfer',
|
|
1717
|
-
'feComposite',
|
|
1718
|
-
'feConvolveMatrix',
|
|
1719
|
-
'feDiffuseLighting',
|
|
1720
|
-
'feDisplacementMap',
|
|
1721
|
-
'feDropShadow',
|
|
1722
|
-
'feFlood',
|
|
1723
|
-
'feFuncA',
|
|
1724
|
-
'feFuncB',
|
|
1725
|
-
'feFuncG',
|
|
1726
|
-
'feFuncR',
|
|
1727
|
-
'feGaussainBlur',
|
|
1728
|
-
'feImage',
|
|
1729
|
-
'feMerge',
|
|
1730
|
-
'feMergeNode',
|
|
1731
|
-
'feMorphology',
|
|
1732
|
-
'feOffset',
|
|
1733
|
-
'fePointLight',
|
|
1734
|
-
'feSpecularLighting',
|
|
1735
|
-
'feSpotLight',
|
|
1736
|
-
'feTile',
|
|
1737
|
-
'feTurbulence',
|
|
1738
|
-
'foreignObject',
|
|
1739
|
-
'linearGradient',
|
|
1740
|
-
'radialGradient',
|
|
1741
|
-
'textPath'
|
|
1742
|
-
];
|
|
1743
|
-
|
|
1744
|
-
var constants$1 = {
|
|
1745
|
-
CASE_SENSITIVE_TAG_NAMES: CASE_SENSITIVE_TAG_NAMES$1
|
|
1746
|
-
};
|
|
1747
|
-
|
|
1748
|
-
var node = {};
|
|
1706
|
+
var utilities = {};
|
|
1749
1707
|
|
|
1750
1708
|
var lib$1 = {};
|
|
1751
1709
|
|
|
1710
|
+
var lib = {};
|
|
1711
|
+
|
|
1752
1712
|
var hasRequiredLib$1;
|
|
1753
1713
|
|
|
1754
1714
|
function requireLib$1 () {
|
|
1755
|
-
if (hasRequiredLib$1) return lib
|
|
1715
|
+
if (hasRequiredLib$1) return lib;
|
|
1756
1716
|
hasRequiredLib$1 = 1;
|
|
1757
1717
|
(function (exports) {
|
|
1758
1718
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1809,10 +1769,12 @@
|
|
|
1809
1769
|
exports.CDATA = ElementType.CDATA;
|
|
1810
1770
|
/** Type for <!doctype ...> */
|
|
1811
1771
|
exports.Doctype = ElementType.Doctype;
|
|
1812
|
-
} (lib
|
|
1813
|
-
return lib
|
|
1772
|
+
} (lib));
|
|
1773
|
+
return lib;
|
|
1814
1774
|
}
|
|
1815
1775
|
|
|
1776
|
+
var node = {};
|
|
1777
|
+
|
|
1816
1778
|
var hasRequiredNode;
|
|
1817
1779
|
|
|
1818
1780
|
function requireNode () {
|
|
@@ -1845,29 +1807,14 @@
|
|
|
1845
1807
|
return __assign.apply(this, arguments);
|
|
1846
1808
|
};
|
|
1847
1809
|
Object.defineProperty(node, "__esModule", { value: true });
|
|
1848
|
-
node.cloneNode = node.hasChildren = node.isDocument = node.isDirective = node.isComment = node.isText = node.isCDATA = node.isTag = node.Element = node.Document = node.NodeWithChildren = node.ProcessingInstruction = node.Comment = node.Text = node.DataNode = node.Node = void 0;
|
|
1810
|
+
node.cloneNode = node.hasChildren = node.isDocument = node.isDirective = node.isComment = node.isText = node.isCDATA = node.isTag = node.Element = node.Document = node.CDATA = node.NodeWithChildren = node.ProcessingInstruction = node.Comment = node.Text = node.DataNode = node.Node = void 0;
|
|
1849
1811
|
var domelementtype_1 = requireLib$1();
|
|
1850
|
-
var nodeTypes = new Map([
|
|
1851
|
-
[domelementtype_1.ElementType.Tag, 1],
|
|
1852
|
-
[domelementtype_1.ElementType.Script, 1],
|
|
1853
|
-
[domelementtype_1.ElementType.Style, 1],
|
|
1854
|
-
[domelementtype_1.ElementType.Directive, 1],
|
|
1855
|
-
[domelementtype_1.ElementType.Text, 3],
|
|
1856
|
-
[domelementtype_1.ElementType.CDATA, 4],
|
|
1857
|
-
[domelementtype_1.ElementType.Comment, 8],
|
|
1858
|
-
[domelementtype_1.ElementType.Root, 9],
|
|
1859
|
-
]);
|
|
1860
1812
|
/**
|
|
1861
1813
|
* This object will be used as the prototype for Nodes when creating a
|
|
1862
1814
|
* DOM-Level-1-compliant structure.
|
|
1863
1815
|
*/
|
|
1864
1816
|
var Node = /** @class */ (function () {
|
|
1865
|
-
|
|
1866
|
-
*
|
|
1867
|
-
* @param type The type of the node.
|
|
1868
|
-
*/
|
|
1869
|
-
function Node(type) {
|
|
1870
|
-
this.type = type;
|
|
1817
|
+
function Node() {
|
|
1871
1818
|
/** Parent of the node */
|
|
1872
1819
|
this.parent = null;
|
|
1873
1820
|
/** Previous sibling */
|
|
@@ -1879,19 +1826,6 @@
|
|
|
1879
1826
|
/** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
|
|
1880
1827
|
this.endIndex = null;
|
|
1881
1828
|
}
|
|
1882
|
-
Object.defineProperty(Node.prototype, "nodeType", {
|
|
1883
|
-
// Read-only aliases
|
|
1884
|
-
/**
|
|
1885
|
-
* [DOM spec](https://dom.spec.whatwg.org/#dom-node-nodetype)-compatible
|
|
1886
|
-
* node {@link type}.
|
|
1887
|
-
*/
|
|
1888
|
-
get: function () {
|
|
1889
|
-
var _a;
|
|
1890
|
-
return (_a = nodeTypes.get(this.type)) !== null && _a !== void 0 ? _a : 1;
|
|
1891
|
-
},
|
|
1892
|
-
enumerable: false,
|
|
1893
|
-
configurable: true
|
|
1894
|
-
});
|
|
1895
1829
|
Object.defineProperty(Node.prototype, "parentNode", {
|
|
1896
1830
|
// Read-write aliases for properties
|
|
1897
1831
|
/**
|
|
@@ -1954,11 +1888,10 @@
|
|
|
1954
1888
|
var DataNode = /** @class */ (function (_super) {
|
|
1955
1889
|
__extends(DataNode, _super);
|
|
1956
1890
|
/**
|
|
1957
|
-
* @param type The type of the node
|
|
1958
1891
|
* @param data The content of the data node
|
|
1959
1892
|
*/
|
|
1960
|
-
function DataNode(
|
|
1961
|
-
var _this = _super.call(this
|
|
1893
|
+
function DataNode(data) {
|
|
1894
|
+
var _this = _super.call(this) || this;
|
|
1962
1895
|
_this.data = data;
|
|
1963
1896
|
return _this;
|
|
1964
1897
|
}
|
|
@@ -1984,9 +1917,18 @@
|
|
|
1984
1917
|
*/
|
|
1985
1918
|
var Text = /** @class */ (function (_super) {
|
|
1986
1919
|
__extends(Text, _super);
|
|
1987
|
-
function Text(
|
|
1988
|
-
|
|
1920
|
+
function Text() {
|
|
1921
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1922
|
+
_this.type = domelementtype_1.ElementType.Text;
|
|
1923
|
+
return _this;
|
|
1989
1924
|
}
|
|
1925
|
+
Object.defineProperty(Text.prototype, "nodeType", {
|
|
1926
|
+
get: function () {
|
|
1927
|
+
return 3;
|
|
1928
|
+
},
|
|
1929
|
+
enumerable: false,
|
|
1930
|
+
configurable: true
|
|
1931
|
+
});
|
|
1990
1932
|
return Text;
|
|
1991
1933
|
}(DataNode));
|
|
1992
1934
|
node.Text = Text;
|
|
@@ -1995,9 +1937,18 @@
|
|
|
1995
1937
|
*/
|
|
1996
1938
|
var Comment = /** @class */ (function (_super) {
|
|
1997
1939
|
__extends(Comment, _super);
|
|
1998
|
-
function Comment(
|
|
1999
|
-
|
|
1940
|
+
function Comment() {
|
|
1941
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1942
|
+
_this.type = domelementtype_1.ElementType.Comment;
|
|
1943
|
+
return _this;
|
|
2000
1944
|
}
|
|
1945
|
+
Object.defineProperty(Comment.prototype, "nodeType", {
|
|
1946
|
+
get: function () {
|
|
1947
|
+
return 8;
|
|
1948
|
+
},
|
|
1949
|
+
enumerable: false,
|
|
1950
|
+
configurable: true
|
|
1951
|
+
});
|
|
2001
1952
|
return Comment;
|
|
2002
1953
|
}(DataNode));
|
|
2003
1954
|
node.Comment = Comment;
|
|
@@ -2007,10 +1958,18 @@
|
|
|
2007
1958
|
var ProcessingInstruction = /** @class */ (function (_super) {
|
|
2008
1959
|
__extends(ProcessingInstruction, _super);
|
|
2009
1960
|
function ProcessingInstruction(name, data) {
|
|
2010
|
-
var _this = _super.call(this,
|
|
1961
|
+
var _this = _super.call(this, data) || this;
|
|
2011
1962
|
_this.name = name;
|
|
1963
|
+
_this.type = domelementtype_1.ElementType.Directive;
|
|
2012
1964
|
return _this;
|
|
2013
1965
|
}
|
|
1966
|
+
Object.defineProperty(ProcessingInstruction.prototype, "nodeType", {
|
|
1967
|
+
get: function () {
|
|
1968
|
+
return 1;
|
|
1969
|
+
},
|
|
1970
|
+
enumerable: false,
|
|
1971
|
+
configurable: true
|
|
1972
|
+
});
|
|
2014
1973
|
return ProcessingInstruction;
|
|
2015
1974
|
}(DataNode));
|
|
2016
1975
|
node.ProcessingInstruction = ProcessingInstruction;
|
|
@@ -2020,11 +1979,10 @@
|
|
|
2020
1979
|
var NodeWithChildren = /** @class */ (function (_super) {
|
|
2021
1980
|
__extends(NodeWithChildren, _super);
|
|
2022
1981
|
/**
|
|
2023
|
-
* @param type Type of the node.
|
|
2024
1982
|
* @param children Children of the node. Only certain node types can have children.
|
|
2025
1983
|
*/
|
|
2026
|
-
function NodeWithChildren(
|
|
2027
|
-
var _this = _super.call(this
|
|
1984
|
+
function NodeWithChildren(children) {
|
|
1985
|
+
var _this = _super.call(this) || this;
|
|
2028
1986
|
_this.children = children;
|
|
2029
1987
|
return _this;
|
|
2030
1988
|
}
|
|
@@ -2065,14 +2023,40 @@
|
|
|
2065
2023
|
return NodeWithChildren;
|
|
2066
2024
|
}(Node));
|
|
2067
2025
|
node.NodeWithChildren = NodeWithChildren;
|
|
2026
|
+
var CDATA = /** @class */ (function (_super) {
|
|
2027
|
+
__extends(CDATA, _super);
|
|
2028
|
+
function CDATA() {
|
|
2029
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2030
|
+
_this.type = domelementtype_1.ElementType.CDATA;
|
|
2031
|
+
return _this;
|
|
2032
|
+
}
|
|
2033
|
+
Object.defineProperty(CDATA.prototype, "nodeType", {
|
|
2034
|
+
get: function () {
|
|
2035
|
+
return 4;
|
|
2036
|
+
},
|
|
2037
|
+
enumerable: false,
|
|
2038
|
+
configurable: true
|
|
2039
|
+
});
|
|
2040
|
+
return CDATA;
|
|
2041
|
+
}(NodeWithChildren));
|
|
2042
|
+
node.CDATA = CDATA;
|
|
2068
2043
|
/**
|
|
2069
2044
|
* The root node of the document.
|
|
2070
2045
|
*/
|
|
2071
2046
|
var Document = /** @class */ (function (_super) {
|
|
2072
2047
|
__extends(Document, _super);
|
|
2073
|
-
function Document(
|
|
2074
|
-
|
|
2048
|
+
function Document() {
|
|
2049
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2050
|
+
_this.type = domelementtype_1.ElementType.Root;
|
|
2051
|
+
return _this;
|
|
2075
2052
|
}
|
|
2053
|
+
Object.defineProperty(Document.prototype, "nodeType", {
|
|
2054
|
+
get: function () {
|
|
2055
|
+
return 9;
|
|
2056
|
+
},
|
|
2057
|
+
enumerable: false,
|
|
2058
|
+
configurable: true
|
|
2059
|
+
});
|
|
2076
2060
|
return Document;
|
|
2077
2061
|
}(NodeWithChildren));
|
|
2078
2062
|
node.Document = Document;
|
|
@@ -2093,11 +2077,19 @@
|
|
|
2093
2077
|
: name === "style"
|
|
2094
2078
|
? domelementtype_1.ElementType.Style
|
|
2095
2079
|
: domelementtype_1.ElementType.Tag; }
|
|
2096
|
-
var _this = _super.call(this,
|
|
2080
|
+
var _this = _super.call(this, children) || this;
|
|
2097
2081
|
_this.name = name;
|
|
2098
2082
|
_this.attribs = attribs;
|
|
2083
|
+
_this.type = type;
|
|
2099
2084
|
return _this;
|
|
2100
2085
|
}
|
|
2086
|
+
Object.defineProperty(Element.prototype, "nodeType", {
|
|
2087
|
+
get: function () {
|
|
2088
|
+
return 1;
|
|
2089
|
+
},
|
|
2090
|
+
enumerable: false,
|
|
2091
|
+
configurable: true
|
|
2092
|
+
});
|
|
2101
2093
|
Object.defineProperty(Element.prototype, "tagName", {
|
|
2102
2094
|
// DOM Level 1 aliases
|
|
2103
2095
|
/**
|
|
@@ -2182,7 +2174,7 @@
|
|
|
2182
2174
|
node.isDocument = isDocument;
|
|
2183
2175
|
/**
|
|
2184
2176
|
* @param node Node to check.
|
|
2185
|
-
* @returns `true` if the node
|
|
2177
|
+
* @returns `true` if the node has children, `false` otherwise.
|
|
2186
2178
|
*/
|
|
2187
2179
|
function hasChildren(node) {
|
|
2188
2180
|
return Object.prototype.hasOwnProperty.call(node, "children");
|
|
@@ -2220,7 +2212,7 @@
|
|
|
2220
2212
|
}
|
|
2221
2213
|
else if (isCDATA(node)) {
|
|
2222
2214
|
var children = recursive ? cloneChildren(node.children) : [];
|
|
2223
|
-
var clone_2 = new
|
|
2215
|
+
var clone_2 = new CDATA(children);
|
|
2224
2216
|
children.forEach(function (child) { return (child.parent = clone_2); });
|
|
2225
2217
|
result = clone_2;
|
|
2226
2218
|
}
|
|
@@ -2264,181 +2256,10 @@
|
|
|
2264
2256
|
return node;
|
|
2265
2257
|
}
|
|
2266
2258
|
|
|
2267
|
-
var constants = constants$1;
|
|
2268
|
-
var domhandler = requireNode();
|
|
2269
|
-
|
|
2270
|
-
var CASE_SENSITIVE_TAG_NAMES = constants.CASE_SENSITIVE_TAG_NAMES;
|
|
2271
|
-
|
|
2272
|
-
var Comment = domhandler.Comment;
|
|
2273
|
-
var Element = domhandler.Element;
|
|
2274
|
-
var ProcessingInstruction = domhandler.ProcessingInstruction;
|
|
2275
|
-
var Text = domhandler.Text;
|
|
2276
|
-
|
|
2277
|
-
var caseSensitiveTagNamesMap = {};
|
|
2278
|
-
var tagName;
|
|
2279
|
-
|
|
2280
|
-
for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES.length; i < len; i++) {
|
|
2281
|
-
tagName = CASE_SENSITIVE_TAG_NAMES[i];
|
|
2282
|
-
caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
|
|
2283
|
-
}
|
|
2284
|
-
|
|
2285
|
-
/**
|
|
2286
|
-
* Gets case-sensitive tag name.
|
|
2287
|
-
*
|
|
2288
|
-
* @param {string} tagName - Tag name in lowercase.
|
|
2289
|
-
* @return {string|undefined} - Case-sensitive tag name.
|
|
2290
|
-
*/
|
|
2291
|
-
function getCaseSensitiveTagName(tagName) {
|
|
2292
|
-
return caseSensitiveTagNamesMap[tagName];
|
|
2293
|
-
}
|
|
2294
|
-
|
|
2295
|
-
/**
|
|
2296
|
-
* Formats DOM attributes to a hash map.
|
|
2297
|
-
*
|
|
2298
|
-
* @param {NamedNodeMap} attributes - List of attributes.
|
|
2299
|
-
* @return {object} - Map of attribute name to value.
|
|
2300
|
-
*/
|
|
2301
|
-
function formatAttributes(attributes) {
|
|
2302
|
-
var result = {};
|
|
2303
|
-
var attribute;
|
|
2304
|
-
// `NamedNodeMap` is array-like
|
|
2305
|
-
for (var i = 0, len = attributes.length; i < len; i++) {
|
|
2306
|
-
attribute = attributes[i];
|
|
2307
|
-
result[attribute.name] = attribute.value;
|
|
2308
|
-
}
|
|
2309
|
-
return result;
|
|
2310
|
-
}
|
|
2311
|
-
|
|
2312
|
-
/**
|
|
2313
|
-
* Corrects the tag name if it is case-sensitive (SVG).
|
|
2314
|
-
* Otherwise, returns the lowercase tag name (HTML).
|
|
2315
|
-
*
|
|
2316
|
-
* @param {string} tagName - Lowercase tag name.
|
|
2317
|
-
* @return {string} - Formatted tag name.
|
|
2318
|
-
*/
|
|
2319
|
-
function formatTagName(tagName) {
|
|
2320
|
-
tagName = tagName.toLowerCase();
|
|
2321
|
-
var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
|
|
2322
|
-
if (caseSensitiveTagName) {
|
|
2323
|
-
return caseSensitiveTagName;
|
|
2324
|
-
}
|
|
2325
|
-
return tagName;
|
|
2326
|
-
}
|
|
2327
|
-
|
|
2328
|
-
/**
|
|
2329
|
-
* Transforms DOM nodes to `domhandler` nodes.
|
|
2330
|
-
*
|
|
2331
|
-
* @param {NodeList} nodes - DOM nodes.
|
|
2332
|
-
* @param {Element|null} [parent=null] - Parent node.
|
|
2333
|
-
* @param {string} [directive] - Directive.
|
|
2334
|
-
* @return {Array<Comment|Element|ProcessingInstruction|Text>}
|
|
2335
|
-
*/
|
|
2336
|
-
function formatDOM$1(nodes, parent, directive) {
|
|
2337
|
-
parent = parent || null;
|
|
2338
|
-
var result = [];
|
|
2339
|
-
|
|
2340
|
-
for (var index = 0, len = nodes.length; index < len; index++) {
|
|
2341
|
-
var node = nodes[index];
|
|
2342
|
-
var current;
|
|
2343
|
-
|
|
2344
|
-
// set the node data given the type
|
|
2345
|
-
switch (node.nodeType) {
|
|
2346
|
-
case 1:
|
|
2347
|
-
// script, style, or tag
|
|
2348
|
-
current = new Element(
|
|
2349
|
-
formatTagName(node.nodeName),
|
|
2350
|
-
formatAttributes(node.attributes)
|
|
2351
|
-
);
|
|
2352
|
-
current.children = formatDOM$1(node.childNodes, current);
|
|
2353
|
-
break;
|
|
2354
|
-
|
|
2355
|
-
case 3:
|
|
2356
|
-
current = new Text(node.nodeValue);
|
|
2357
|
-
break;
|
|
2358
|
-
|
|
2359
|
-
case 8:
|
|
2360
|
-
current = new Comment(node.nodeValue);
|
|
2361
|
-
break;
|
|
2362
|
-
|
|
2363
|
-
default:
|
|
2364
|
-
continue;
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
|
-
// set previous node next
|
|
2368
|
-
var prev = result[index - 1] || null;
|
|
2369
|
-
if (prev) {
|
|
2370
|
-
prev.next = current;
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
// set properties for current node
|
|
2374
|
-
current.parent = parent;
|
|
2375
|
-
current.prev = prev;
|
|
2376
|
-
current.next = null;
|
|
2377
|
-
|
|
2378
|
-
result.push(current);
|
|
2379
|
-
}
|
|
2380
|
-
|
|
2381
|
-
if (directive) {
|
|
2382
|
-
current = new ProcessingInstruction(
|
|
2383
|
-
directive.substring(0, directive.indexOf(' ')).toLowerCase(),
|
|
2384
|
-
directive
|
|
2385
|
-
);
|
|
2386
|
-
current.next = result[0] || null;
|
|
2387
|
-
current.parent = parent;
|
|
2388
|
-
result.unshift(current);
|
|
2389
|
-
|
|
2390
|
-
if (result[1]) {
|
|
2391
|
-
result[1].prev = result[0];
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
|
|
2395
|
-
return result;
|
|
2396
|
-
}
|
|
2397
|
-
|
|
2398
|
-
var utilities = {
|
|
2399
|
-
formatAttributes: formatAttributes,
|
|
2400
|
-
formatDOM: formatDOM$1
|
|
2401
|
-
};
|
|
2402
|
-
|
|
2403
|
-
var domparser = domparser_1;
|
|
2404
|
-
var formatDOM = utilities.formatDOM;
|
|
2405
|
-
|
|
2406
|
-
var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
|
|
2407
|
-
|
|
2408
|
-
/**
|
|
2409
|
-
* Parses HTML string to DOM nodes in browser.
|
|
2410
|
-
*
|
|
2411
|
-
* @param {string} html - HTML markup.
|
|
2412
|
-
* @return {DomElement[]} - DOM elements.
|
|
2413
|
-
*/
|
|
2414
|
-
function HTMLDOMParser(html) {
|
|
2415
|
-
if (typeof html !== 'string') {
|
|
2416
|
-
throw new TypeError('First argument must be a string');
|
|
2417
|
-
}
|
|
2418
|
-
|
|
2419
|
-
if (html === '') {
|
|
2420
|
-
return [];
|
|
2421
|
-
}
|
|
2422
|
-
|
|
2423
|
-
// match directive
|
|
2424
|
-
var match = html.match(DIRECTIVE_REGEX);
|
|
2425
|
-
var directive;
|
|
2426
|
-
|
|
2427
|
-
if (match && match[1]) {
|
|
2428
|
-
directive = match[1];
|
|
2429
|
-
}
|
|
2430
|
-
|
|
2431
|
-
return formatDOM(domparser(html), null, directive);
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
var htmlToDom = HTMLDOMParser;
|
|
2435
|
-
|
|
2436
|
-
var lib = {};
|
|
2437
|
-
|
|
2438
2259
|
var hasRequiredLib;
|
|
2439
2260
|
|
|
2440
2261
|
function requireLib () {
|
|
2441
|
-
if (hasRequiredLib) return lib;
|
|
2262
|
+
if (hasRequiredLib) return lib$1;
|
|
2442
2263
|
hasRequiredLib = 1;
|
|
2443
2264
|
(function (exports) {
|
|
2444
2265
|
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -2458,12 +2279,10 @@
|
|
|
2458
2279
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2459
2280
|
exports.DomHandler = void 0;
|
|
2460
2281
|
var domelementtype_1 = requireLib$1();
|
|
2461
|
-
var
|
|
2282
|
+
var node_js_1 = requireNode();
|
|
2462
2283
|
__exportStar(requireNode(), exports);
|
|
2463
|
-
var reWhitespace = /\s+/g;
|
|
2464
2284
|
// Default options
|
|
2465
2285
|
var defaultOpts = {
|
|
2466
|
-
normalizeWhitespace: false,
|
|
2467
2286
|
withStartIndices: false,
|
|
2468
2287
|
withEndIndices: false,
|
|
2469
2288
|
xmlMode: false,
|
|
@@ -2478,7 +2297,7 @@
|
|
|
2478
2297
|
/** The elements of the DOM */
|
|
2479
2298
|
this.dom = [];
|
|
2480
2299
|
/** The root element for the DOM */
|
|
2481
|
-
this.root = new
|
|
2300
|
+
this.root = new node_js_1.Document(this.dom);
|
|
2482
2301
|
/** Indicated whether parsing has been completed. */
|
|
2483
2302
|
this.done = false;
|
|
2484
2303
|
/** Stack of open tags. */
|
|
@@ -2506,7 +2325,7 @@
|
|
|
2506
2325
|
// Resets the handler back to starting state
|
|
2507
2326
|
DomHandler.prototype.onreset = function () {
|
|
2508
2327
|
this.dom = [];
|
|
2509
|
-
this.root = new
|
|
2328
|
+
this.root = new node_js_1.Document(this.dom);
|
|
2510
2329
|
this.done = false;
|
|
2511
2330
|
this.tagStack = [this.root];
|
|
2512
2331
|
this.lastNode = null;
|
|
@@ -2534,29 +2353,20 @@
|
|
|
2534
2353
|
};
|
|
2535
2354
|
DomHandler.prototype.onopentag = function (name, attribs) {
|
|
2536
2355
|
var type = this.options.xmlMode ? domelementtype_1.ElementType.Tag : undefined;
|
|
2537
|
-
var element = new
|
|
2356
|
+
var element = new node_js_1.Element(name, attribs, undefined, type);
|
|
2538
2357
|
this.addNode(element);
|
|
2539
2358
|
this.tagStack.push(element);
|
|
2540
2359
|
};
|
|
2541
2360
|
DomHandler.prototype.ontext = function (data) {
|
|
2542
|
-
var normalizeWhitespace = this.options.normalizeWhitespace;
|
|
2543
2361
|
var lastNode = this.lastNode;
|
|
2544
2362
|
if (lastNode && lastNode.type === domelementtype_1.ElementType.Text) {
|
|
2545
|
-
|
|
2546
|
-
lastNode.data = (lastNode.data + data).replace(reWhitespace, " ");
|
|
2547
|
-
}
|
|
2548
|
-
else {
|
|
2549
|
-
lastNode.data += data;
|
|
2550
|
-
}
|
|
2363
|
+
lastNode.data += data;
|
|
2551
2364
|
if (this.options.withEndIndices) {
|
|
2552
2365
|
lastNode.endIndex = this.parser.endIndex;
|
|
2553
2366
|
}
|
|
2554
2367
|
}
|
|
2555
2368
|
else {
|
|
2556
|
-
|
|
2557
|
-
data = data.replace(reWhitespace, " ");
|
|
2558
|
-
}
|
|
2559
|
-
var node = new node_1.Text(data);
|
|
2369
|
+
var node = new node_js_1.Text(data);
|
|
2560
2370
|
this.addNode(node);
|
|
2561
2371
|
this.lastNode = node;
|
|
2562
2372
|
}
|
|
@@ -2566,7 +2376,7 @@
|
|
|
2566
2376
|
this.lastNode.data += data;
|
|
2567
2377
|
return;
|
|
2568
2378
|
}
|
|
2569
|
-
var node = new
|
|
2379
|
+
var node = new node_js_1.Comment(data);
|
|
2570
2380
|
this.addNode(node);
|
|
2571
2381
|
this.lastNode = node;
|
|
2572
2382
|
};
|
|
@@ -2574,8 +2384,8 @@
|
|
|
2574
2384
|
this.lastNode = null;
|
|
2575
2385
|
};
|
|
2576
2386
|
DomHandler.prototype.oncdatastart = function () {
|
|
2577
|
-
var text = new
|
|
2578
|
-
var node = new
|
|
2387
|
+
var text = new node_js_1.Text("");
|
|
2388
|
+
var node = new node_js_1.CDATA([text]);
|
|
2579
2389
|
this.addNode(node);
|
|
2580
2390
|
text.parent = node;
|
|
2581
2391
|
this.lastNode = text;
|
|
@@ -2584,7 +2394,7 @@
|
|
|
2584
2394
|
this.lastNode = null;
|
|
2585
2395
|
};
|
|
2586
2396
|
DomHandler.prototype.onprocessinginstruction = function (name, data) {
|
|
2587
|
-
var node = new
|
|
2397
|
+
var node = new node_js_1.ProcessingInstruction(name, data);
|
|
2588
2398
|
this.addNode(node);
|
|
2589
2399
|
};
|
|
2590
2400
|
DomHandler.prototype.handleCallback = function (error) {
|
|
@@ -2616,10 +2426,219 @@
|
|
|
2616
2426
|
}());
|
|
2617
2427
|
exports.DomHandler = DomHandler;
|
|
2618
2428
|
exports.default = DomHandler;
|
|
2619
|
-
} (lib));
|
|
2620
|
-
return lib;
|
|
2429
|
+
} (lib$1));
|
|
2430
|
+
return lib$1;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
var constants$1 = {};
|
|
2434
|
+
|
|
2435
|
+
/**
|
|
2436
|
+
* SVG elements are case-sensitive.
|
|
2437
|
+
*
|
|
2438
|
+
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#svg_elements_a_to_z}
|
|
2439
|
+
*/
|
|
2440
|
+
|
|
2441
|
+
constants$1.CASE_SENSITIVE_TAG_NAMES = [
|
|
2442
|
+
'animateMotion',
|
|
2443
|
+
'animateTransform',
|
|
2444
|
+
'clipPath',
|
|
2445
|
+
'feBlend',
|
|
2446
|
+
'feColorMatrix',
|
|
2447
|
+
'feComponentTransfer',
|
|
2448
|
+
'feComposite',
|
|
2449
|
+
'feConvolveMatrix',
|
|
2450
|
+
'feDiffuseLighting',
|
|
2451
|
+
'feDisplacementMap',
|
|
2452
|
+
'feDropShadow',
|
|
2453
|
+
'feFlood',
|
|
2454
|
+
'feFuncA',
|
|
2455
|
+
'feFuncB',
|
|
2456
|
+
'feFuncG',
|
|
2457
|
+
'feFuncR',
|
|
2458
|
+
'feGaussainBlur',
|
|
2459
|
+
'feImage',
|
|
2460
|
+
'feMerge',
|
|
2461
|
+
'feMergeNode',
|
|
2462
|
+
'feMorphology',
|
|
2463
|
+
'feOffset',
|
|
2464
|
+
'fePointLight',
|
|
2465
|
+
'feSpecularLighting',
|
|
2466
|
+
'feSpotLight',
|
|
2467
|
+
'feTile',
|
|
2468
|
+
'feTurbulence',
|
|
2469
|
+
'foreignObject',
|
|
2470
|
+
'linearGradient',
|
|
2471
|
+
'radialGradient',
|
|
2472
|
+
'textPath'
|
|
2473
|
+
];
|
|
2474
|
+
|
|
2475
|
+
var domhandler = requireLib();
|
|
2476
|
+
var constants = constants$1;
|
|
2477
|
+
|
|
2478
|
+
var CASE_SENSITIVE_TAG_NAMES = constants.CASE_SENSITIVE_TAG_NAMES;
|
|
2479
|
+
|
|
2480
|
+
var Comment = domhandler.Comment;
|
|
2481
|
+
var Element = domhandler.Element;
|
|
2482
|
+
var ProcessingInstruction = domhandler.ProcessingInstruction;
|
|
2483
|
+
var Text = domhandler.Text;
|
|
2484
|
+
|
|
2485
|
+
var caseSensitiveTagNamesMap = {};
|
|
2486
|
+
var tagName;
|
|
2487
|
+
|
|
2488
|
+
for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES.length; i < len; i++) {
|
|
2489
|
+
tagName = CASE_SENSITIVE_TAG_NAMES[i];
|
|
2490
|
+
caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* Gets case-sensitive tag name.
|
|
2495
|
+
*
|
|
2496
|
+
* @param {string} tagName - Tag name in lowercase.
|
|
2497
|
+
* @returns {string|undefined} - Case-sensitive tag name.
|
|
2498
|
+
*/
|
|
2499
|
+
function getCaseSensitiveTagName(tagName) {
|
|
2500
|
+
return caseSensitiveTagNamesMap[tagName];
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
/**
|
|
2504
|
+
* Formats DOM attributes to a hash map.
|
|
2505
|
+
*
|
|
2506
|
+
* @param {NamedNodeMap} attributes - List of attributes.
|
|
2507
|
+
* @returns {object} - Map of attribute name to value.
|
|
2508
|
+
*/
|
|
2509
|
+
function formatAttributes(attributes) {
|
|
2510
|
+
var result = {};
|
|
2511
|
+
var attribute;
|
|
2512
|
+
// `NamedNodeMap` is array-like
|
|
2513
|
+
for (var i = 0, len = attributes.length; i < len; i++) {
|
|
2514
|
+
attribute = attributes[i];
|
|
2515
|
+
result[attribute.name] = attribute.value;
|
|
2516
|
+
}
|
|
2517
|
+
return result;
|
|
2621
2518
|
}
|
|
2622
2519
|
|
|
2520
|
+
/**
|
|
2521
|
+
* Corrects the tag name if it is case-sensitive (SVG).
|
|
2522
|
+
* Otherwise, returns the lowercase tag name (HTML).
|
|
2523
|
+
*
|
|
2524
|
+
* @param {string} tagName - Lowercase tag name.
|
|
2525
|
+
* @returns {string} - Formatted tag name.
|
|
2526
|
+
*/
|
|
2527
|
+
function formatTagName(tagName) {
|
|
2528
|
+
tagName = tagName.toLowerCase();
|
|
2529
|
+
var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
|
|
2530
|
+
if (caseSensitiveTagName) {
|
|
2531
|
+
return caseSensitiveTagName;
|
|
2532
|
+
}
|
|
2533
|
+
return tagName;
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
/**
|
|
2537
|
+
* Transforms DOM nodes to `domhandler` nodes.
|
|
2538
|
+
*
|
|
2539
|
+
* @param {NodeList} nodes - DOM nodes.
|
|
2540
|
+
* @param {Element|null} [parent=null] - Parent node.
|
|
2541
|
+
* @param {string} [directive] - Directive.
|
|
2542
|
+
* @returns {Array<Comment|Element|ProcessingInstruction|Text>}
|
|
2543
|
+
*/
|
|
2544
|
+
function formatDOM$1(nodes, parent, directive) {
|
|
2545
|
+
parent = parent || null;
|
|
2546
|
+
var result = [];
|
|
2547
|
+
|
|
2548
|
+
for (var index = 0, len = nodes.length; index < len; index++) {
|
|
2549
|
+
var node = nodes[index];
|
|
2550
|
+
var current;
|
|
2551
|
+
|
|
2552
|
+
// set the node data given the type
|
|
2553
|
+
switch (node.nodeType) {
|
|
2554
|
+
case 1:
|
|
2555
|
+
// script, style, or tag
|
|
2556
|
+
current = new Element(
|
|
2557
|
+
formatTagName(node.nodeName),
|
|
2558
|
+
formatAttributes(node.attributes)
|
|
2559
|
+
);
|
|
2560
|
+
current.children = formatDOM$1(node.childNodes, current);
|
|
2561
|
+
break;
|
|
2562
|
+
|
|
2563
|
+
case 3:
|
|
2564
|
+
current = new Text(node.nodeValue);
|
|
2565
|
+
break;
|
|
2566
|
+
|
|
2567
|
+
case 8:
|
|
2568
|
+
current = new Comment(node.nodeValue);
|
|
2569
|
+
break;
|
|
2570
|
+
|
|
2571
|
+
default:
|
|
2572
|
+
continue;
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
// set previous node next
|
|
2576
|
+
var prev = result[index - 1] || null;
|
|
2577
|
+
if (prev) {
|
|
2578
|
+
prev.next = current;
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
// set properties for current node
|
|
2582
|
+
current.parent = parent;
|
|
2583
|
+
current.prev = prev;
|
|
2584
|
+
current.next = null;
|
|
2585
|
+
|
|
2586
|
+
result.push(current);
|
|
2587
|
+
}
|
|
2588
|
+
|
|
2589
|
+
if (directive) {
|
|
2590
|
+
current = new ProcessingInstruction(
|
|
2591
|
+
directive.substring(0, directive.indexOf(' ')).toLowerCase(),
|
|
2592
|
+
directive
|
|
2593
|
+
);
|
|
2594
|
+
current.next = result[0] || null;
|
|
2595
|
+
current.parent = parent;
|
|
2596
|
+
result.unshift(current);
|
|
2597
|
+
|
|
2598
|
+
if (result[1]) {
|
|
2599
|
+
result[1].prev = result[0];
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
|
|
2603
|
+
return result;
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
utilities.formatAttributes = formatAttributes;
|
|
2607
|
+
utilities.formatDOM = formatDOM$1;
|
|
2608
|
+
|
|
2609
|
+
var domparser = domparser_1;
|
|
2610
|
+
var formatDOM = utilities.formatDOM;
|
|
2611
|
+
|
|
2612
|
+
var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
|
|
2613
|
+
|
|
2614
|
+
/**
|
|
2615
|
+
* Parses HTML string to DOM nodes in browser.
|
|
2616
|
+
*
|
|
2617
|
+
* @param {string} html - HTML markup.
|
|
2618
|
+
* @return {DomElement[]} - DOM elements.
|
|
2619
|
+
*/
|
|
2620
|
+
function HTMLDOMParser(html) {
|
|
2621
|
+
if (typeof html !== 'string') {
|
|
2622
|
+
throw new TypeError('First argument must be a string');
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
if (html === '') {
|
|
2626
|
+
return [];
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
// match directive
|
|
2630
|
+
var match = html.match(DIRECTIVE_REGEX);
|
|
2631
|
+
var directive;
|
|
2632
|
+
|
|
2633
|
+
if (match && match[1]) {
|
|
2634
|
+
directive = match[1];
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
return formatDOM(domparser(html), null, directive);
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
var htmlToDom = HTMLDOMParser;
|
|
2641
|
+
|
|
2623
2642
|
var domToReact = domToReact_1;
|
|
2624
2643
|
var attributesToProps = attributesToProps$2;
|
|
2625
2644
|
var htmlToDOM = htmlToDom;
|