Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
elgs committed Feb 28, 2021
1 parent 513dd37 commit 03c8681
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
72 changes: 71 additions & 1 deletion README.md
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);
```
4 changes: 2 additions & 2 deletions parse5-htmlparser2-tree-adapter/test.js
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);
2 changes: 1 addition & 1 deletion parse5/tests/test_parse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as parse5 from '../lib/index.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>');

Expand Down
2 changes: 1 addition & 1 deletion parse5/tests/test_parseFragment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as parse5 from '../lib/index.js';
import * as parse5 from 'https://deno.land/x/parse5/parse5/lib/index.js';

const documentFragment = parse5.parseFragment('<table></table>');

Expand Down
2 changes: 1 addition & 1 deletion parse5/tests/test_serialize.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as parse5 from '../lib/index.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>');

Expand Down

0 comments on commit 03c8681

Please sign in to comment.