Skip to content

Commit 5f4f945

Browse files
authored
Merge pull request #695 from dart-lang/merge-html-package
Merge `package:html`
2 parents 4a94350 + 0e9dfda commit 5f4f945

File tree

100 files changed

+87088
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+87088
-0
lines changed

.github/ISSUE_TEMPLATE/html.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: "package:html"
3+
about: "Create a bug or file a feature request against package:html."
4+
labels: "package:html"
5+
---

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
- changed-files:
6161
- any-glob-to-any-file: 'pkgs/graphs/**'
6262

63+
'package:html':
64+
- changed-files:
65+
- any-glob-to-any-file: 'pkgs/html/**'
66+
6367
'package:json_rpc_2':
6468
- changed-files:
6569
- any-glob-to-any-file: 'pkgs/json_rpc_2/**'

.github/workflows/html.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: package:html
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- '.github/workflows/html.yml'
9+
- 'pkgs/html/**'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/html.yml'
14+
- 'pkgs/html/**'
15+
schedule:
16+
- cron: "0 0 * * 0"
17+
18+
env:
19+
PUB_ENVIRONMENT: bot.github
20+
21+
22+
defaults:
23+
run:
24+
working-directory: pkgs/html/
25+
26+
jobs:
27+
analyze:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
fail-fast: false
31+
steps:
32+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
33+
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
34+
with:
35+
sdk: dev
36+
- id: install
37+
run: dart pub get
38+
- run: dart format --output=none --set-exit-if-changed .
39+
if: steps.install.outcome == 'success'
40+
- run: dart analyze --fatal-infos
41+
if: steps.install.outcome == 'success'
42+
43+
test:
44+
needs: analyze
45+
runs-on: ${{ matrix.os }}
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
os: [ubuntu-latest]
50+
sdk: [3.2, stable, dev]
51+
steps:
52+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
53+
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
54+
with:
55+
sdk: ${{ matrix.sdk }}
56+
- id: install
57+
run: dart pub get
58+
- run: dart test --platform vm
59+
if: steps.install.outcome == 'success'
60+
- run: dart test --platform chrome
61+
if: steps.install.outcome == 'success'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ don't naturally belong to other topic monorepos (like
2828
| [file](pkgs/file/) | A pluggable, mockable file system abstraction for Dart. | [![pub package](https://img.shields.io/pub/v/file.svg)](https://pub.dev/packages/file) |
2929
| [file_testing](pkgs/file_testing/) | Testing utilities for package:file (published but unlisted). | [![pub package](https://img.shields.io/pub/v/file_testing.svg)](https://pub.dev/packages/file_testing) |
3030
| [graphs](pkgs/graphs/) | Graph algorithms that operate on graphs in any representation | [![pub package](https://img.shields.io/pub/v/graphs.svg)](https://pub.dev/packages/graphs) |
31+
| [html](pkgs/html/) | APIs for parsing and manipulating HTML content outside the browser. | [![pub package](https://img.shields.io/pub/v/html.svg)](https://pub.dev/packages/html) |
3132
| [json_rpc_2](pkgs/json_rpc_2/) | Utilities to write a client or server using the JSON-RPC 2.0 spec. | [![pub package](https://img.shields.io/pub/v/json_rpc_2.svg)](https://pub.dev/packages/json_rpc_2) |
3233
| [mime](pkgs/mime/) | Utilities for handling media (MIME) types. | [![pub package](https://img.shields.io/pub/v/mime.svg)](https://pub.dev/packages/mime) |
3334
| [oauth2](pkgs/oauth2/) | A client library for authenticatingand making requests via OAuth2. | [![pub package](https://img.shields.io/pub/v/oauth2.svg)](https://pub.dev/packages/oauth2) |

pkgs/html/.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Don’t commit the following directories created by pub.
2+
.pub
3+
.dart_tool/
4+
build/
5+
packages
6+
.packages
7+
8+
# Or the files created by dart2js.
9+
*.dart.js
10+
*.dart.precompiled.js
11+
*.js_
12+
*.js.deps
13+
*.js.map
14+
*.sw?
15+
.idea/
16+
.pub/
17+
18+
# Include when developing application packages.
19+
pubspec.lock

pkgs/html/CHANGELOG.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
## 0.15.5
2+
3+
- Require Dart `3.2`.
4+
- Move to `dart-lang/tools` monorepo.
5+
6+
## 0.15.4
7+
8+
- Widen the dependency on `package:csslib`.
9+
- Require Dart `2.19`.
10+
11+
## 0.15.3
12+
13+
- Added package topics to the pubspec file.
14+
15+
## 0.15.2
16+
17+
- Add additional types at the API boundary (in `lib/parser.dart` and others).
18+
- Adopted the `package:dart_flutter_team_lints` linting rules.
19+
- Fixed an issue with `querySelector` where it would fail in some cases with
20+
descendant or sibling combinators (#157).
21+
- Add an API example in `example/`.
22+
23+
## 0.15.1
24+
25+
- Move `htmlSerializeEscape` to its own library,
26+
`package:html/html_escape.dart`, which is exported from
27+
`package:html/dom_parsing.dart`.
28+
- Use more non-growable lists, and type annotations on List literals.
29+
- Switch analysis option `implicit-casts: false` to `strict-casts: true`.
30+
31+
## 0.15.0
32+
33+
- Migrate to null safety.
34+
- Drop `lastPhase`, `beforeRcDataPhase`, and `container` fields from
35+
`HtmlParser` class. These fields never had a value other than `null`.
36+
37+
## 0.14.0+4
38+
39+
- Fix a bug parsing bad HTML where a 'button' end tag needs to close other
40+
elements.
41+
42+
## 0.14.0+3
43+
44+
- Fix spans generated for HTML with higher-plane unicode characters
45+
(eg. emojis).
46+
47+
## 0.14.0+2
48+
49+
- Support `package:css` `>=0.13.2 <0.17.0`.
50+
51+
## 0.14.0+1
52+
53+
- Support `package:css` `>=0.13.2 <0.16.0`.
54+
55+
## 0.14.0
56+
57+
*BREAKING CHANGES*
58+
59+
- Drop support for encodings other than UTF-8 and ASCII.
60+
- Removed `parser_console.dart` library.
61+
62+
## 0.13.4+1
63+
64+
* Fixes to readme and pubspec.
65+
66+
## 0.13.4
67+
68+
* Require Dart 2.0 stable.
69+
70+
## 0.13.3+3
71+
72+
* Do not use this tag in our systems - there was an earlier version of it
73+
pointing to a different commit, that is still in some caches.
74+
75+
* Fix missing_return analyzer errors in `processStartTag` and `processEndTag`
76+
methods.
77+
78+
## 0.13.3+2
79+
80+
* Set max SDK version to `<3.0.0`, and adjust other dependencies.
81+
82+
## 0.13.3+1
83+
84+
* Updated SDK version to 2.0.0-dev.17.0
85+
86+
## 0.13.3
87+
88+
* Update the signatures of `FilteredElementList.indexOf` and
89+
`FilteredElementList.lastIndexOf` to include type annotations.
90+
91+
## 0.13.2+2
92+
93+
* Update signature for implementations of `Iterable.singleWhere` to include
94+
optional argument.
95+
96+
## 0.13.2+1
97+
98+
* Changed the implementation of `Set` and `List` classes to use base classes
99+
from `dart:collection`.
100+
101+
## 0.13.2
102+
103+
* Support the latest release of `pkg/csslib`.
104+
105+
## 0.13.1
106+
* Update Set.difference to take a Set<Object>.
107+
108+
## 0.13.0
109+
110+
* **BREAKING** Fix all [strong mode][] errors and warnings.
111+
This involved adding more precise types on some public APIs, which is why it
112+
may break users.
113+
114+
[strong mode]: https://github.com/dart-lang/dev_compiler/blob/master/STRONG_MODE.md
115+
116+
#### Pub version 0.12.2+2
117+
* Support `csslib` versions `0.13.x`.
118+
119+
#### Pub version 0.12.2+1
120+
* Exclude `.packages` file from the published package.
121+
122+
#### Pub version 0.12.2
123+
* Added `Element.endSourceSpan`, containing the span of a closing tag.
124+
125+
#### Pub version 0.12.0+1
126+
* Support `csslib` version `0.12.0`.
127+
128+
#### Rename to package:html 0.12.0
129+
* package has been renamed to `html`
130+
131+
#### Pub version 0.12.0
132+
* switch from `source_maps`' `Span` class to `source_span`'s
133+
`SourceSpan` class.
134+
135+
#### Pub version 0.11.0+2
136+
* expand the version constraint for csslib.
137+
138+
#### Pub version 0.10.0+1
139+
* use a more recent source_maps version.
140+
141+
#### Pub version 0.10.0
142+
* fix how document fragments are added in NodeList.add/addAll/insertAll.
143+
144+
#### Pub version 0.9.2-dev
145+
* add Node.text, Node.append, Document.documentElement
146+
* add Text.data, deprecate Node.value and Text.value.
147+
* deprecate Node.$dom_nodeType
148+
* added querySelector/querySelectorAll, deprecated query/queryAll.
149+
This matches the current APIs in dart:html.

pkgs/html/LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2006-2012 The Authors
2+
3+
Contributors:
4+
James Graham - [email protected]
5+
Anne van Kesteren - [email protected]
6+
Lachlan Hunt - [email protected]
7+
Matt McDonald - [email protected]
8+
9+
Ian Hickson (Google) - [email protected]
10+
Thomas Broyer - [email protected]
11+
Jacques Distler - [email protected]
12+
Henri Sivonen - [email protected]
13+
Adam Barth - [email protected]
14+
Eric Seidel - [email protected]
15+
The Mozilla Foundation (contributions from Henri Sivonen since 2008)
16+
David Flanagan (Mozilla) - [email protected]
17+
Google LLC (contributed the Dart port) - [email protected]
18+
19+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
20+
21+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pkgs/html/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/html.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/html.yaml)
2+
[![pub package](https://img.shields.io/pub/v/html.svg)](https://pub.dev/packages/html)
3+
[![package publisher](https://img.shields.io/pub/publisher/html.svg)](https://pub.dev/packages/html/publisher)
4+
5+
A Dart implementation of an HTML5 parser.
6+
7+
## Usage
8+
9+
Parsing HTML is easy!
10+
11+
```dart
12+
import 'package:html/parser.dart';
13+
14+
void main() {
15+
var document = parse(
16+
'<body>Hello world! <a href="www.html5rocks.com">HTML5 rocks!');
17+
print(document.outerHtml);
18+
}
19+
```
20+
21+
You can pass a String or list of bytes to `parse`. There's also `parseFragment`
22+
for parsing a document fragment, and `HtmlParser` if you want more low level
23+
control.
24+
25+
## Background
26+
27+
This package was a port of the Python
28+
[html5lib](https://github.com/html5lib/html5lib-python) library.

pkgs/html/analysis_options.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include: package:dart_flutter_team_lints/analysis_options.yaml
2+
3+
analyzer:
4+
language:
5+
strict-casts: true
6+
strict-raw-types: true
7+
errors:
8+
lines_longer_than_80_chars: ignore
9+
# https://github.com/dart-lang/linter/issues/1649
10+
prefer_collection_literals: ignore

pkgs/html/example/main.dart

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import 'package:html/dom.dart';
2+
import 'package:html/dom_parsing.dart';
3+
import 'package:html/parser.dart';
4+
5+
void main(List<String> args) {
6+
var document = parse('''
7+
<body>
8+
<h2>Header 1</h2>
9+
<p>Text.</p>
10+
<h2>Header 2</h2>
11+
More text.
12+
<br/>
13+
</body>''');
14+
15+
// outerHtml output
16+
print('outer html:');
17+
print(document.outerHtml);
18+
19+
print('');
20+
21+
// visitor output
22+
print('html visitor:');
23+
_Visitor().visit(document);
24+
}
25+
26+
// Note: this example visitor doesn't handle things like printing attributes and
27+
// such.
28+
class _Visitor extends TreeVisitor {
29+
String indent = '';
30+
31+
@override
32+
void visitText(Text node) {
33+
if (node.data.trim().isNotEmpty) {
34+
print('$indent${node.data.trim()}');
35+
}
36+
}
37+
38+
@override
39+
void visitElement(Element node) {
40+
if (isVoidElement(node.localName)) {
41+
print('$indent<${node.localName}/>');
42+
} else {
43+
print('$indent<${node.localName}>');
44+
indent += ' ';
45+
visitChildren(node);
46+
indent = indent.substring(0, indent.length - 2);
47+
print('$indent</${node.localName}>');
48+
}
49+
}
50+
51+
@override
52+
void visitChildren(Node node) {
53+
for (var child in node.nodes) {
54+
visit(child);
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)