Skip to content

Commit

Permalink
Merge pull request #695 from dart-lang/merge-html-package
Browse files Browse the repository at this point in the history
Merge `package:html`
  • Loading branch information
mosuem authored Oct 29, 2024
2 parents 4a94350 + 0e9dfda commit 5f4f945
Show file tree
Hide file tree
Showing 100 changed files with 87,088 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:html"
about: "Create a bug or file a feature request against package:html."
labels: "package:html"
---
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
- changed-files:
- any-glob-to-any-file: 'pkgs/graphs/**'

'package:html':
- changed-files:
- any-glob-to-any-file: 'pkgs/html/**'

'package:json_rpc_2':
- changed-files:
- any-glob-to-any-file: 'pkgs/json_rpc_2/**'
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/html.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: package:html

on:
# Run on PRs and pushes to the default branch.
push:
branches: [ main ]
paths:
- '.github/workflows/html.yml'
- 'pkgs/html/**'
pull_request:
branches: [ main ]
paths:
- '.github/workflows/html.yml'
- 'pkgs/html/**'
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github


defaults:
run:
working-directory: pkgs/html/

jobs:
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: dev
- id: install
run: dart pub get
- run: dart format --output=none --set-exit-if-changed .
if: steps.install.outcome == 'success'
- run: dart analyze --fatal-infos
if: steps.install.outcome == 'success'

test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
sdk: [3.2, stable, dev]
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{ matrix.sdk }}
- id: install
run: dart pub get
- run: dart test --platform vm
if: steps.install.outcome == 'success'
- run: dart test --platform chrome
if: steps.install.outcome == 'success'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ don't naturally belong to other topic monorepos (like
| [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) |
| [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) |
| [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) |
| [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) |
| [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) |
| [mime](pkgs/mime/) | Utilities for handling media (MIME) types. | [![pub package](https://img.shields.io/pub/v/mime.svg)](https://pub.dev/packages/mime) |
| [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) |
Expand Down
19 changes: 19 additions & 0 deletions pkgs/html/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Don’t commit the following directories created by pub.
.pub
.dart_tool/
build/
packages
.packages

# Or the files created by dart2js.
*.dart.js
*.dart.precompiled.js
*.js_
*.js.deps
*.js.map
*.sw?
.idea/
.pub/

# Include when developing application packages.
pubspec.lock
149 changes: 149 additions & 0 deletions pkgs/html/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
## 0.15.5

- Require Dart `3.2`.
- Move to `dart-lang/tools` monorepo.

## 0.15.4

- Widen the dependency on `package:csslib`.
- Require Dart `2.19`.

## 0.15.3

- Added package topics to the pubspec file.

## 0.15.2

- Add additional types at the API boundary (in `lib/parser.dart` and others).
- Adopted the `package:dart_flutter_team_lints` linting rules.
- Fixed an issue with `querySelector` where it would fail in some cases with
descendant or sibling combinators (#157).
- Add an API example in `example/`.

## 0.15.1

- Move `htmlSerializeEscape` to its own library,
`package:html/html_escape.dart`, which is exported from
`package:html/dom_parsing.dart`.
- Use more non-growable lists, and type annotations on List literals.
- Switch analysis option `implicit-casts: false` to `strict-casts: true`.

## 0.15.0

- Migrate to null safety.
- Drop `lastPhase`, `beforeRcDataPhase`, and `container` fields from
`HtmlParser` class. These fields never had a value other than `null`.

## 0.14.0+4

- Fix a bug parsing bad HTML where a 'button' end tag needs to close other
elements.

## 0.14.0+3

- Fix spans generated for HTML with higher-plane unicode characters
(eg. emojis).

## 0.14.0+2

- Support `package:css` `>=0.13.2 <0.17.0`.

## 0.14.0+1

- Support `package:css` `>=0.13.2 <0.16.0`.

## 0.14.0

*BREAKING CHANGES*

- Drop support for encodings other than UTF-8 and ASCII.
- Removed `parser_console.dart` library.

## 0.13.4+1

* Fixes to readme and pubspec.

## 0.13.4

* Require Dart 2.0 stable.

## 0.13.3+3

* Do not use this tag in our systems - there was an earlier version of it
pointing to a different commit, that is still in some caches.

* Fix missing_return analyzer errors in `processStartTag` and `processEndTag`
methods.

## 0.13.3+2

* Set max SDK version to `<3.0.0`, and adjust other dependencies.

## 0.13.3+1

* Updated SDK version to 2.0.0-dev.17.0

## 0.13.3

* Update the signatures of `FilteredElementList.indexOf` and
`FilteredElementList.lastIndexOf` to include type annotations.

## 0.13.2+2

* Update signature for implementations of `Iterable.singleWhere` to include
optional argument.

## 0.13.2+1

* Changed the implementation of `Set` and `List` classes to use base classes
from `dart:collection`.

## 0.13.2

* Support the latest release of `pkg/csslib`.

## 0.13.1
* Update Set.difference to take a Set<Object>.

## 0.13.0

* **BREAKING** Fix all [strong mode][] errors and warnings.
This involved adding more precise types on some public APIs, which is why it
may break users.

[strong mode]: https://github.com/dart-lang/dev_compiler/blob/master/STRONG_MODE.md

#### Pub version 0.12.2+2
* Support `csslib` versions `0.13.x`.

#### Pub version 0.12.2+1
* Exclude `.packages` file from the published package.

#### Pub version 0.12.2
* Added `Element.endSourceSpan`, containing the span of a closing tag.

#### Pub version 0.12.0+1
* Support `csslib` version `0.12.0`.

#### Rename to package:html 0.12.0
* package has been renamed to `html`

#### Pub version 0.12.0
* switch from `source_maps`' `Span` class to `source_span`'s
`SourceSpan` class.

#### Pub version 0.11.0+2
* expand the version constraint for csslib.

#### Pub version 0.10.0+1
* use a more recent source_maps version.

#### Pub version 0.10.0
* fix how document fragments are added in NodeList.add/addAll/insertAll.

#### Pub version 0.9.2-dev
* add Node.text, Node.append, Document.documentElement
* add Text.data, deprecate Node.value and Text.value.
* deprecate Node.$dom_nodeType
* added querySelector/querySelectorAll, deprecated query/queryAll.
This matches the current APIs in dart:html.
23 changes: 23 additions & 0 deletions pkgs/html/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2006-2012 The Authors

Contributors:
James Graham - [email protected]
Anne van Kesteren - [email protected]
Lachlan Hunt - [email protected]
Matt McDonald - [email protected]
Sam Ruby - [email protected]
Ian Hickson (Google) - [email protected]
Thomas Broyer - [email protected]
Jacques Distler - [email protected]
Henri Sivonen - [email protected]
Adam Barth - [email protected]
Eric Seidel - [email protected]
The Mozilla Foundation (contributions from Henri Sivonen since 2008)
David Flanagan (Mozilla) - [email protected]
Google LLC (contributed the Dart port) - [email protected]

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
28 changes: 28 additions & 0 deletions pkgs/html/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/html.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/html.yaml)
[![pub package](https://img.shields.io/pub/v/html.svg)](https://pub.dev/packages/html)
[![package publisher](https://img.shields.io/pub/publisher/html.svg)](https://pub.dev/packages/html/publisher)

A Dart implementation of an HTML5 parser.

## Usage

Parsing HTML is easy!

```dart
import 'package:html/parser.dart';
void main() {
var document = parse(
'<body>Hello world! <a href="www.html5rocks.com">HTML5 rocks!');
print(document.outerHtml);
}
```

You can pass a String or list of bytes to `parse`. There's also `parseFragment`
for parsing a document fragment, and `HtmlParser` if you want more low level
control.

## Background

This package was a port of the Python
[html5lib](https://github.com/html5lib/html5lib-python) library.
10 changes: 10 additions & 0 deletions pkgs/html/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-raw-types: true
errors:
lines_longer_than_80_chars: ignore
# https://github.com/dart-lang/linter/issues/1649
prefer_collection_literals: ignore
57 changes: 57 additions & 0 deletions pkgs/html/example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:html/dom.dart';
import 'package:html/dom_parsing.dart';
import 'package:html/parser.dart';

void main(List<String> args) {
var document = parse('''
<body>
<h2>Header 1</h2>
<p>Text.</p>
<h2>Header 2</h2>
More text.
<br/>
</body>''');

// outerHtml output
print('outer html:');
print(document.outerHtml);

print('');

// visitor output
print('html visitor:');
_Visitor().visit(document);
}

// Note: this example visitor doesn't handle things like printing attributes and
// such.
class _Visitor extends TreeVisitor {
String indent = '';

@override
void visitText(Text node) {
if (node.data.trim().isNotEmpty) {
print('$indent${node.data.trim()}');
}
}

@override
void visitElement(Element node) {
if (isVoidElement(node.localName)) {
print('$indent<${node.localName}/>');
} else {
print('$indent<${node.localName}>');
indent += ' ';
visitChildren(node);
indent = indent.substring(0, indent.length - 2);
print('$indent</${node.localName}>');
}
}

@override
void visitChildren(Node node) {
for (var child in node.nodes) {
visit(child);
}
}
}
Loading

0 comments on commit 5f4f945

Please sign in to comment.