-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
76 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,72 @@ | ||
# parse5 | ||
Ported from inikulin/parse5 but for Deno. | ||
|
||
Ported from inikulin/parse5 v6.0.1 but for Deno. | ||
|
||
This project is a port from: | ||
|
||
- parse5 | ||
- parse5-htmlparser2-tree-adapter | ||
|
||
modules from inikulin/parse5 at v6.0.1. | ||
|
||
Other modules involved with Node's stream api are not ported. | ||
|
||
### Why? | ||
|
||
- It runs natively in Browser. | ||
- It works with Deno. | ||
- It's pure Javascript, no Node API. | ||
|
||
### Sample code | ||
|
||
#### parse | ||
|
||
```js | ||
import * as parse5 from "https://deno.land/x/parse5/parse5/lib/index.js"; | ||
|
||
const document = parse5.parse( | ||
"<!DOCTYPE html><html><head></head><body>Hi there!</body></html>" | ||
); | ||
console.log(document.childNodes[1].tagName); //> 'html' | ||
``` | ||
|
||
#### parseFragment | ||
|
||
```js | ||
import * as parse5 from "https://deno.land/x/parse5/parse5/lib/index.js"; | ||
|
||
const documentFragment = parse5.parseFragment("<table></table>"); | ||
console.log(documentFragment.childNodes[0].tagName); //> 'table' | ||
|
||
// Parses the html fragment in the context of the parsed <table> element. | ||
const trFragment = parse5.parseFragment( | ||
documentFragment.childNodes[0], | ||
"<tr><td>Shake it, baby</td></tr>" | ||
); | ||
console.log(trFragment.childNodes[0].childNodes[0].tagName); //> 'td' | ||
``` | ||
|
||
#### serialize | ||
|
||
```js | ||
import * as parse5 from "https://deno.land/x/parse5/parse5/lib/index.js"; | ||
|
||
const document = parse5.parse( | ||
"<!DOCTYPE html><html><head></head><body>Hi there!</body></html>" | ||
); | ||
// Serializes a document. | ||
const html = parse5.serialize(document); | ||
|
||
// Serializes the <html> element content. | ||
const str = parse5.serialize(document.childNodes[1]); | ||
console.log(str); //> '<head></head><body>Hi there!</body>' | ||
``` | ||
|
||
#### htmlparser2Adapter | ||
```js | ||
import * as parse5 from 'https://deno.land/x/parse5/parse5/lib/index.js'; | ||
import * as htmlparser2Adapter from 'https://deno.land/x/parse5/parse5-htmlparser2-tree-adapter/lib/index.js'; | ||
|
||
const document = parse5.parse('<div></div>', { treeAdapter: htmlparser2Adapter }); | ||
console.log(document); | ||
``` |
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,7 +1,7 @@ | ||
// deno run test.js | ||
|
||
import * as parse5 from '../parse5/lib/index.js'; | ||
import * as htmlparser2Adapter from './lib/index.js'; | ||
import * as parse5 from 'https://deno.land/x/parse5/parse5/lib/index.js'; | ||
import * as htmlparser2Adapter from 'https://deno.land/x/parse5/parse5-htmlparser2-tree-adapter/lib/index.js'; | ||
|
||
const document = parse5.parse('<div></div>', { treeAdapter: htmlparser2Adapter }); | ||
console.log(document); |
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