html-react-parser 3.0.0 → 3.0.3
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
CHANGED
|
@@ -62,6 +62,7 @@ parse('<p>Hello, World!</p>'); // React.createElement('p', {}, 'Hello, World!')
|
|
|
62
62
|
- [Financial Contributors](#financial-contributors)
|
|
63
63
|
- [Individuals](#individuals)
|
|
64
64
|
- [Organizations](#organizations)
|
|
65
|
+
- [Enterprise](#enterprise)
|
|
65
66
|
- [Support](#support)
|
|
66
67
|
- [License](#license)
|
|
67
68
|
|
|
@@ -540,6 +541,12 @@ Support this project with your organization. Your logo will show up here with a
|
|
|
540
541
|
[](https://opencollective.com/html-react-parser/organization/8/website)
|
|
541
542
|
[](https://opencollective.com/html-react-parser/organization/9/website)
|
|
542
543
|
|
|
544
|
+
## Enterprise
|
|
545
|
+
|
|
546
|
+
Available as part of the Tidelift Subscription.
|
|
547
|
+
|
|
548
|
+
The maintainers of html-react-parser and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-html-react-parser?utm_source=npm-html-react-parser&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
|
549
|
+
|
|
543
550
|
## Support
|
|
544
551
|
|
|
545
552
|
- [GitHub Sponsors](https://b.remarkabl.org/github-sponsors)
|
|
@@ -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 () {
|
|
@@ -1564,13 +1565,15 @@
|
|
|
1564
1565
|
);
|
|
1565
1566
|
};
|
|
1566
1567
|
|
|
1568
|
+
var DOMParser = typeof window === 'object' && window.DOMParser;
|
|
1569
|
+
|
|
1567
1570
|
/**
|
|
1568
1571
|
* DOMParser (performance: slow).
|
|
1569
1572
|
*
|
|
1570
1573
|
* @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
|
|
1571
1574
|
*/
|
|
1572
|
-
if (typeof
|
|
1573
|
-
var domParser = new
|
|
1575
|
+
if (typeof DOMParser === 'function') {
|
|
1576
|
+
var domParser = new DOMParser();
|
|
1574
1577
|
var mimeType = 'text/html';
|
|
1575
1578
|
|
|
1576
1579
|
/**
|
|
@@ -1596,7 +1599,7 @@
|
|
|
1596
1599
|
*
|
|
1597
1600
|
* @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
|
|
1598
1601
|
*/
|
|
1599
|
-
if (document.implementation) {
|
|
1602
|
+
if (typeof document === 'object' && document.implementation) {
|
|
1600
1603
|
var doc = document.implementation.createHTMLDocument();
|
|
1601
1604
|
|
|
1602
1605
|
/**
|
|
@@ -1608,7 +1611,8 @@
|
|
|
1608
1611
|
*/
|
|
1609
1612
|
parseFromDocument = function (html, tagName) {
|
|
1610
1613
|
if (tagName) {
|
|
1611
|
-
doc.documentElement.
|
|
1614
|
+
var element = doc.documentElement.querySelector(tagName);
|
|
1615
|
+
element.innerHTML = html;
|
|
1612
1616
|
return doc;
|
|
1613
1617
|
}
|
|
1614
1618
|
|
|
@@ -1622,7 +1626,9 @@
|
|
|
1622
1626
|
*
|
|
1623
1627
|
* @see https://developer.mozilla.org/docs/Web/HTML/Element/template
|
|
1624
1628
|
*/
|
|
1625
|
-
var template =
|
|
1629
|
+
var template =
|
|
1630
|
+
typeof document === 'object' ? document.createElement('template') : {};
|
|
1631
|
+
|
|
1626
1632
|
var parseFromTemplate;
|
|
1627
1633
|
|
|
1628
1634
|
if (template.content) {
|
|
@@ -1663,24 +1669,25 @@
|
|
|
1663
1669
|
// the created document may come with filler head/body elements,
|
|
1664
1670
|
// so make sure to remove them if they don't actually exist
|
|
1665
1671
|
if (!HEAD_TAG_REGEX.test(html)) {
|
|
1666
|
-
element = doc.
|
|
1672
|
+
element = doc.querySelector(HEAD);
|
|
1667
1673
|
if (element) {
|
|
1668
1674
|
element.parentNode.removeChild(element);
|
|
1669
1675
|
}
|
|
1670
1676
|
}
|
|
1671
1677
|
|
|
1672
1678
|
if (!BODY_TAG_REGEX.test(html)) {
|
|
1673
|
-
element = doc.
|
|
1679
|
+
element = doc.querySelector(BODY);
|
|
1674
1680
|
if (element) {
|
|
1675
1681
|
element.parentNode.removeChild(element);
|
|
1676
1682
|
}
|
|
1677
1683
|
}
|
|
1678
1684
|
|
|
1679
|
-
return doc.
|
|
1685
|
+
return doc.querySelectorAll(HTML);
|
|
1680
1686
|
|
|
1681
1687
|
case HEAD:
|
|
1682
1688
|
case BODY:
|
|
1683
|
-
|
|
1689
|
+
doc = parseFromDocument(html);
|
|
1690
|
+
elements = doc.querySelectorAll(firstTagName);
|
|
1684
1691
|
|
|
1685
1692
|
// if there's a sibling element, then return both elements
|
|
1686
1693
|
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
|
|
@@ -1693,9 +1700,8 @@
|
|
|
1693
1700
|
if (parseFromTemplate) {
|
|
1694
1701
|
return parseFromTemplate(html);
|
|
1695
1702
|
}
|
|
1696
|
-
|
|
1697
|
-
return
|
|
1698
|
-
.childNodes;
|
|
1703
|
+
element = parseFromDocument(html, BODY).querySelector(BODY);
|
|
1704
|
+
return element.childNodes;
|
|
1699
1705
|
}
|
|
1700
1706
|
}
|
|
1701
1707
|
|