-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from remarkablemark/build/dependencies
build(package): upgrade `domhandler` to v4 and `htmlparser2` to v6
- Loading branch information
Showing
7 changed files
with
43 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
var Parser = require('htmlparser2/lib/Parser').Parser; | ||
var DomHandler = require('domhandler').DomHandler; | ||
|
||
var unsetRootParent = require('./utilities').unsetRootParent; | ||
|
||
/** | ||
* Parses HTML string to DOM nodes in Node.js. | ||
* | ||
* This is the same method as `require('htmlparser2').parseDOM` | ||
* https://github.com/fb55/htmlparser2/blob/v4.1.0/src/index.ts#L18-L22 | ||
* https://github.com/fb55/htmlparser2/blob/v6.0.0/src/index.ts#L29-L41 | ||
* | ||
* @param {string} html - HTML markup. | ||
* @param {DomHandlerOptions} [options] - Parser options (https://github.com/fb55/domhandler/tree/v3.3.0#readme). | ||
* @param {DomHandlerOptions} [options] - Parser options (https://github.com/fb55/domhandler/tree/v4.0.0#readme). | ||
* @return {Array<Comment|Element|ProcessingInstruction|Text>} - DOM nodes. | ||
*/ | ||
function HTMLDOMParser(html, options) { | ||
if (typeof html !== 'string') { | ||
throw new TypeError('First argument must be a string.'); | ||
} | ||
|
||
if (!html) { | ||
if (html === '') { | ||
return []; | ||
} | ||
|
||
var handler = new DomHandler(undefined, options); | ||
new Parser(handler, options).end(html); | ||
return handler.dom; | ||
return unsetRootParent(handler.dom); | ||
} | ||
|
||
module.exports = HTMLDOMParser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// TypeScript Version: 4.1 | ||
|
||
type Nodes = Array<Comment | Element | ProcessingInstruction | Text>; | ||
|
||
/** | ||
* Sets root parent to null. | ||
* | ||
* @param nodes | ||
* @return | ||
*/ | ||
export function unsetRootParent(nodes: Nodes): Nodes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Sets root parent to null. | ||
* | ||
* @param {Array<Comment|Element|ProcessingInstruction|Text>} nodes | ||
* @return {Array<Comment|Element|ProcessingInstruction|Text>} | ||
*/ | ||
function unsetRootParent(nodes) { | ||
for (var index = 0, len = nodes.length; index < len; index++) { | ||
var node = nodes[index]; | ||
node.parent = null; | ||
} | ||
return nodes; | ||
} | ||
|
||
module.exports = { | ||
unsetRootParent: unsetRootParent | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters