Repository: remarkablemark/html-react-parser (ts)

Issue:
Export `Text` from `domhandler`
## Expected Behavior

```import { Text } from 'html-react-parser'``` should work

## Actual Behavior

It fails because `Text` is only exported in type definition, but not in `index.js` file.

## Steps to Reproduce

```import { Text } from 'html-react-parser'```

## Reproducible Demo


## Environment

- Version: v3.0.4
- Platform: macOS
- Browser: Chrome


Pull request:
fix(index): export domhandler classes
## What is the motivation for this pull request?

fix(index): export domhandler classes

Fixes #777

## What is the current behavior?

Only `domhandler` class Element is exported

## What is the new behavior?

Export additional `domhandler` classes:

- Comment
- ProcessingInstruction
- Text

## Checklist:

- [x] [Conventional Commits](https://www.conventionalcommits.org/)
- [x] Tests
- [ ] Documentation
- [ ] Types

Patch:
diff --git a/.size-limit.json b/.size-limit.json
index aaa687b..b6162e7 100644
--- a/.size-limit.json
+++ b/.size-limit.json
@@ -1,6 +1,6 @@
 [
   {
     "path": "dist/html-react-parser.min.js",
-    "limit": "10.531 KB"
+    "limit": "10.524 KB"
   }
 ]
diff --git a/index.d.ts b/index.d.ts
index feb848a..a41b8b4 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,22 +1,23 @@
 // TypeScript Version: 4.7
+/* eslint-disable no-undef, no-unused-vars */
 
-import { ParserOptions } from 'htmlparser2';
 import {
   Comment,
-  DomHandlerOptions,
   Element,
   Node,
   ProcessingInstruction,
-  Text
+  Text,
+  type DomHandlerOptions
 } from 'domhandler';
 import htmlToDOM from 'html-dom-parser';
+import { ParserOptions } from 'htmlparser2';
 
 import attributesToProps from './lib/attributes-to-props';
 import domToReact from './lib/dom-to-react';
 
 export { attributesToProps, domToReact, htmlToDOM };
 export type HTMLParser2Options = ParserOptions & DomHandlerOptions;
-export { Comment, Element, Node, ProcessingInstruction, Text };
+export { Comment, Element, ProcessingInstruction, Text };
 export type DOMNode = Comment | Element | Node | ProcessingInstruction | Text;
 
 export interface HTMLReactParserOptions {
diff --git a/index.js b/index.js
index 7a1fd34..2e82986 100644
--- a/index.js
+++ b/index.js
@@ -1,7 +1,9 @@
-var domToReact = require('./lib/dom-to-react');
-var attributesToProps = require('./lib/attributes-to-props');
+var domhandler = require('domhandler');
 var htmlToDOM = require('html-dom-parser');
 
+var attributesToProps = require('./lib/attributes-to-props');
+var domToReact = require('./lib/dom-to-react');
+
 // support backwards compatibility for ES Module
 htmlToDOM =
   /* istanbul ignore next */
@@ -36,7 +38,12 @@ function HTMLReactParser(html, options) {
 HTMLReactParser.domToReact = domToReact;
 HTMLReactParser.htmlToDOM = htmlToDOM;
 HTMLReactParser.attributesToProps = attributesToProps;
-HTMLReactParser.Element = require('domhandler').Element;
+
+// domhandler
+HTMLReactParser.Comment = domhandler.Comment;
+HTMLReactParser.Element = domhandler.Element;
+HTMLReactParser.ProcessingInstruction = domhandler.ProcessingInstruction;
+HTMLReactParser.Text = domhandler.Text;
 
 // support CommonJS and ES Modules
 module.exports = HTMLReactParser;
diff --git a/index.mjs b/index.mjs
index 018feb9..842eac5 100644
--- a/index.mjs
+++ b/index.mjs
@@ -3,6 +3,11 @@ import HTMLReactParser from './index.js';
 export var domToReact = HTMLReactParser.domToReact;
 export var htmlToDOM = HTMLReactParser.htmlToDOM;
 export var attributesToProps = HTMLReactParser.attributesToProps;
+
+// domhandler
+export var Comment = HTMLReactParser.Comment;
 export var Element = HTMLReactParser.Element;
+export var ProcessingInstruction = HTMLReactParser.ProcessingInstruction;
+export var Text = HTMLReactParser.Text;
 
 export default HTMLReactParser;


Test patch:
diff --git a/test/index.test.js b/test/index.test.js
index 58a88fe..fbbc264 100644
--- a/test/index.test.js
+++ b/test/index.test.js
@@ -1,4 +1,5 @@
 const React = require('react');
+const domhandler = require('domhandler');
 const parse = require('..');
 const { html, svg } = require('./data');
 const { render } = require('./helpers');
@@ -24,6 +25,16 @@ describe('module', () => {
     expect(parse.attributesToProps).toBe(require('../lib/attributes-to-props'));
     expect(parse.attributesToProps).toBeInstanceOf(Function);
   });
+
+  describe('domhandler', () => {
+    it.each(['Comment', 'Element', 'ProcessingInstruction', 'Text'])(
+      'exports %s',
+      name => {
+        expect(parse[name]).toBeInstanceOf(Function);
+        expect(parse[name]).toBe(domhandler[name]);
+      }
+    );
+  });
 });
 
 describe('HTMLReactParser', () => {
diff --git a/test/integration/index.test.js b/test/integration/index.test.js
index a964e3e..6ae39bd 100644
--- a/test/integration/index.test.js
+++ b/test/integration/index.test.js
@@ -1,10 +1,10 @@
 describe.each([
-  ['unminified', '../../dist/html-react-parser'],
-  ['minified', '../../dist/html-react-parser.min']
+  ['minified', '../../dist/html-react-parser.min'],
+  ['unminified', '../../dist/html-react-parser']
 ])('UMD %s', (_type, path) => {
   const parse = require(path);
 
-  it('exports the parser', () => {
+  it('exports parser', () => {
     expect(parse).toBeInstanceOf(Function);
   });
 
@@ -12,15 +12,21 @@ describe.each([
     expect(parse.default).toBeInstanceOf(Function);
   });
 
-  it('exports domToReact', () => {
-    expect(parse.domToReact).toBeInstanceOf(Function);
+  describe('internal', () => {
+    it.each(['attributesToProps', 'domToReact', 'htmlToDOM'])(
+      'exports %s',
+      name => {
+        expect(parse[name]).toBeInstanceOf(Function);
+      }
+    );
   });
 
-  it('exports htmlToDOM', () => {
-    expect(parse.htmlToDOM).toBeInstanceOf(Function);
-  });
-
-  it('exports attributesToProps', () => {
-    expect(parse.attributesToProps).toBeInstanceOf(Function);
+  describe('domhandler', () => {
+    it.each(['Comment', 'Element', 'ProcessingInstruction', 'Text'])(
+      'exports %s',
+      name => {
+        expect(parse[name]).toBeInstanceOf(Function);
+      }
+    );
   });
 });
diff --git a/test/module/index.mjs b/test/module/index.mjs
index 79ed70a..dac2ca6 100644
--- a/test/module/index.mjs
+++ b/test/module/index.mjs
@@ -1,10 +1,16 @@
 import assert from 'assert';
 import parse, {
+  attributesToProps,
   domToReact,
-  htmlToDOM,
-  attributesToProps
+  htmlToDOM
 } from '../../index.mjs';
+import { Comment, Element, ProcessingInstruction, Text } from '../../index.mjs';
 
 [parse, domToReact, htmlToDOM, attributesToProps].forEach(func => {
   assert.strictEqual(typeof func, 'function');
 });
+
+// domhandler
+[Comment, Element, ProcessingInstruction, Text].forEach(func => {
+  assert.strictEqual(typeof func, 'function');
+});