Skip to content

Commit d9e905a

Browse files
committed
Merge remote-tracking branch 'upstream/master' into bugfix/677-swallow-duplicate-ids
2 parents 410157c + 9aac393 commit d9e905a

File tree

10 files changed

+517
-63
lines changed

10 files changed

+517
-63
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: Bug report
3+
about: Something isn't working as intended
4+
title: "[BUG]"
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
<!---
11+
12+
Please do not delete this issue template as it helps us organize and easily work on issues!!
13+
14+
NOTE: Before posting, please make sure you have
15+
1. Searched the README
16+
2. Searched the Issues tab for similar bugs
17+
3. Please provide the required information in the template - HTML code and Html widget configuration
18+
--->
19+
20+
**Describe the bug:**
21+
<!--- Please provide a clear and concise description of the bug --->
22+
23+
**HTML to reproduce the issue:**
24+
<!--- Please provide your HTML code below. If it contains sensitive information please post a minimal reproducible HTML snippet. --->
25+
26+
**`Html` widget configuration:**
27+
<!--- Please provide your HTML widget configuration below --->
28+
29+
**Expected behavior:**
30+
<!--- Expected behavior, if applicable, otherwise please delete --->
31+
32+
**Screenshots:**
33+
<!--- Screenshots can be helpful to analyze your issue. Please delete this section if you don't provide any. --->
34+
35+
**Device details and Flutter/Dart/`flutter_html` versions:**
36+
<!--- These details can be helpful to analyze your issue. Please delete this section if you don't provide any. --->
37+
38+
**Stacktrace/Logcat**
39+
<!--- The error stacktrace if applicable, otherwise please delete --->
40+
41+
**Additional info:**
42+
<!--- Any other info relevant to the bug, otherwise please delete --->
43+
44+
**A picture of a cute animal (not mandatory but encouraged)**
45+
<!--- A picture of a cute animal that would nicely complement this bug report.
46+
If you don't have one, please delete, just know we will be a little disappointed ;) --->
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for flutter_html
4+
title: "[FEATURE]"
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
<!---
11+
12+
Please do not delete this issue template as it helps us organize and easily work on issues!!
13+
14+
NOTE: Before posting, please make sure you have
15+
1. Searched the README
16+
2. Searched the Issues tab for similar feature requests
17+
--->
18+
19+
**Describe your feature request**
20+
<!--- Please provide a clear and concise description of the feature request --->
21+
22+
**Additional context**
23+
<!--- Any other info relevant to the feature request, otherwise please delete --->
24+
25+
**A picture of a cute animal (not mandatory but encouraged)**
26+
<!--- A picture of a cute animal that would nicely complement this feature request.
27+
If you don't have one, please delete, just know we will be a little disappointed ;) --->

.github/ISSUE_TEMPLATE/question.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Question
3+
about: Ask a question about flutter_html
4+
title: "[QUESTION]"
5+
labels: question
6+
assignees: ''
7+
8+
---
9+
10+
<!---
11+
NOTE: Before posting, please make sure you have
12+
1. Searched the README
13+
2. Searched the Issues tab for similar questions
14+
--->
15+
16+
Type question here.
17+
18+
**A picture of a cute animal (not mandatory but encouraged)**
19+
<!--- A picture of a cute animal that would nicely complement this question.
20+
If you don't have one, please delete, just know we will be a little disappointed ;) --->

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ Add the following to your `pubspec.yaml` file:
123123
## Currently Supported Inline CSS Attributes:
124124
| | | | | | | |
125125
|------------------|--------|------------|----------|--------------|------------------------|------------|
126-
|`background-color`| `border` | `color`| `direction`| `display`| `font-family`| `font-feature-settings` |
127-
| `font-size`|`font-style` | `font-weight`| `line-height` | `list-style-type` | `list-style-position`|`padding` |
128-
| `margin`| `text-align`| `text-decoration`| `text-decoration-color`| `text-decoration-style`| `text-shadow` | |
126+
|`background-color`| `border` (including specific directions) | `color`| `direction`| `display`| `font-family`| `font-feature-settings` |
127+
| `font-size`|`font-style` | `font-weight`| `line-height` | `list-style-type` | `list-style-position`|`padding` (including specific directions) |
128+
| `margin` (including specific directions) | `text-align`| `text-decoration`| `text-decoration-color`| `text-decoration-style`| `text-shadow` | |
129129

130130
Don't see a tag or attribute you need? File a feature request or contribute to the project!
131131

@@ -252,6 +252,8 @@ A powerful API that allows you to customize everything when rendering a specific
252252

253253
To use this API, set the key as the tag of the HTML element you wish to provide a custom implementation for, and create a function with the above parameters that returns a `Widget` or `InlineSpan`.
254254

255+
Note: If you add any custom tags, you must add these tags to the [`tagsList`](#tagslist) parameter, otherwise they will not be rendered. See below for an example.
256+
255257
#### Example Usages - customRender:
256258
1. Simple example - rendering custom HTML tags
257259

@@ -276,6 +278,7 @@ Widget html = Html(
276278
);
277279
},
278280
},
281+
tagsList: Html.tags..addAll(["bird", "flutter"]),
279282
);
280283
```
281284

@@ -304,6 +307,8 @@ Widget html = Html(
304307
);
305308
```
306309

310+
</details>
311+
307312
3. Complex example - rendering an `iframe` differently based on whether it is an embedded youtube video or some other embedded content.
308313

309314
<details><summary>View code</summary>

example/lib/main.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ class _MyHomePageState extends State<MyHomePage> {
315315
onImageError: (exception, stackTrace) {
316316
print(exception);
317317
},
318+
onCssParseError: (css, messages) {
319+
print("css that errored: $css");
320+
print("error messages:");
321+
messages.forEach((element) {
322+
print(element);
323+
});
324+
},
318325
),
319326
),
320327
);

lib/flutter_html.dart

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
library flutter_html;
22

3-
//export image render api
4-
export 'package:flutter_html/image_render.dart';
5-
//export style api
6-
export 'package:flutter_html/style.dart';
7-
//export render context api
8-
export 'package:flutter_html/html_parser.dart';
9-
//export src for advanced custom render uses (e.g. casting context.tree)
10-
export 'package:flutter_html/src/layout_element.dart';
11-
export 'package:flutter_html/src/replaced_element.dart';
12-
export 'package:flutter_html/src/styled_element.dart';
13-
export 'package:flutter_html/src/interactable_element.dart';
14-
153
import 'package:flutter/material.dart';
164
import 'package:flutter/rendering.dart';
175
import 'package:flutter_html/html_parser.dart';
186
import 'package:flutter_html/image_render.dart';
197
import 'package:flutter_html/src/html_elements.dart';
208
import 'package:flutter_html/style.dart';
21-
import 'package:webview_flutter/webview_flutter.dart';
229
import 'package:html/dom.dart' as dom;
10+
import 'package:webview_flutter/webview_flutter.dart';
11+
12+
//export render context api
13+
export 'package:flutter_html/html_parser.dart';
14+
//export render context api
15+
export 'package:flutter_html/html_parser.dart';
16+
//export image render api
17+
export 'package:flutter_html/image_render.dart';
18+
//export image render api
19+
export 'package:flutter_html/image_render.dart';
20+
export 'package:flutter_html/src/anchor.dart';
21+
export 'package:flutter_html/src/anchor.dart';
22+
export 'package:flutter_html/src/interactable_element.dart';
23+
export 'package:flutter_html/src/interactable_element.dart';
24+
//export src for advanced custom render uses (e.g. casting context.tree)
25+
export 'package:flutter_html/src/layout_element.dart';
26+
//export src for advanced custom render uses (e.g. casting context.tree)
27+
export 'package:flutter_html/src/layout_element.dart';
28+
export 'package:flutter_html/src/replaced_element.dart';
29+
export 'package:flutter_html/src/replaced_element.dart';
30+
export 'package:flutter_html/src/styled_element.dart';
31+
export 'package:flutter_html/src/styled_element.dart';
32+
//export style api
33+
export 'package:flutter_html/style.dart';
34+
//export style api
35+
export 'package:flutter_html/style.dart';
2336

2437
class Html extends StatelessWidget {
2538
/// The `Html` widget takes HTML as input and displays a RichText
@@ -49,42 +62,46 @@ class Html extends StatelessWidget {
4962
/// See [its wiki page](https://github.com/Sub6Resources/flutter_html/wiki/Style) for more info.
5063
Html({
5164
Key? key,
65+
GlobalKey? anchorKey,
5266
required this.data,
5367
this.onLinkTap,
5468
this.customRender = const {},
5569
this.customImageRenders = const {},
70+
this.onCssParseError,
5671
this.onImageError,
5772
this.onMathError,
5873
this.shrinkWrap = false,
5974
this.onImageTap,
6075
this.tagsList = const [],
6176
this.style = const {},
6277
this.navigationDelegateForIframe,
63-
}) : document = null,
64-
assert (data != null),
65-
anchorKey = GlobalKey(),
78+
}) : document = null,
79+
assert(data != null),
80+
_anchorKey = anchorKey ?? GlobalKey(),
6681
super(key: key);
6782

6883
Html.fromDom({
6984
Key? key,
85+
GlobalKey? anchorKey,
7086
@required this.document,
7187
this.onLinkTap,
7288
this.customRender = const {},
7389
this.customImageRenders = const {},
90+
this.onCssParseError,
7491
this.onImageError,
7592
this.onMathError,
7693
this.shrinkWrap = false,
7794
this.onImageTap,
7895
this.tagsList = const [],
7996
this.style = const {},
8097
this.navigationDelegateForIframe,
81-
}) : data = null,
98+
}) : data = null,
8299
assert(document != null),
83-
anchorKey = GlobalKey(),
100+
_anchorKey = anchorKey ?? GlobalKey(),
84101
super(key: key);
85102

86103
/// A unique key for this Html widget to ensure uniqueness of anchors
87-
final Key anchorKey;
104+
final GlobalKey _anchorKey;
88105

89106
/// The HTML data passed to the widget as a String
90107
final String? data;
@@ -99,14 +116,16 @@ class Html extends StatelessWidget {
99116
/// See the README for more details.
100117
final Map<ImageSourceMatcher, ImageRender> customImageRenders;
101118

119+
/// A function that defines what to do when CSS fails to parse
120+
final OnCssParseError? onCssParseError;
121+
102122
/// A function that defines what to do when an image errors
103123
final ImageErrorListener? onImageError;
104124

105125
/// A function that defines what to do when either <math> or <tex> fails to render
106126
/// You can return a widget here to override the default error widget.
107127
final OnMathError? onMathError;
108128

109-
110129
/// A parameter that should be set when the HTML widget is expected to be
111130
/// flexible
112131
final bool shrinkWrap;
@@ -138,16 +157,18 @@ class Html extends StatelessWidget {
138157

139158
@override
140159
Widget build(BuildContext context) {
141-
final dom.Document doc = data != null ? HtmlParser.parseHTML(data!) : document!;
160+
final dom.Document doc =
161+
data != null ? HtmlParser.parseHTML(data!) : document!;
142162
final double? width = shrinkWrap ? null : MediaQuery.of(context).size.width;
143163

144164
return Container(
145165
width: width,
146166
child: HtmlParser(
147-
key: anchorKey,
167+
key: _anchorKey,
148168
htmlData: doc,
149169
onLinkTap: onLinkTap,
150170
onImageTap: onImageTap,
171+
onCssParseError: onCssParseError,
151172
onImageError: onImageError,
152173
onMathError: onMathError,
153174
shrinkWrap: shrinkWrap,

0 commit comments

Comments
 (0)