Skip to content

Commit c6b030e

Browse files
committed
Merge branch 'master' of https://github.com/Sub6Resources/flutter_html into feature/upgrade-custom-render
� Conflicts: � README.md � lib/flutter_html.dart � lib/html_parser.dart
2 parents 1c7b9e2 + 6de34b9 commit c6b030e

25 files changed

+540
-194
lines changed

CHANGELOG.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,46 @@
1-
## [2.1.1] - July 27, 2021:
1+
## [2.2.1] - December 8, 2021:
2+
* Allow styling on ruby tags
3+
* Allow width/height/alignment styling on table/tr/td tags
4+
* Prevent images causing rebuilding and leaking memory
5+
* Fixes display of list items on iOS with font weights below 400
6+
* Prevent crash on negative margins or paddings
7+
8+
## [2.2.0] - November 29, 2021:
9+
* Explicitly declare multiplatform support
10+
* Extended and fixed list-style (marker) support
11+
* Basic support for height/width css properties
12+
* Support changing scroll physics of SelectableText.rich
13+
* Support text transform css property
14+
* Bumped minimum flutter_math_fork version for Flutter 2.5 compatibility
15+
* Fix styling of iframes
16+
* Fix nested font tag application
17+
* Fix whitespace rendering between list items
18+
* Prevent crash on empty <table> tag and tables with both colspan/rowspan
19+
* Prevent crash on use of negative margins in css
20+
21+
## [2.1.5] - October 7, 2021:
22+
* Ignore unsupported custom style selectors when using fromCss
23+
* Fix SVG tag usage inside tables
24+
* Properly fix regression in usage of line breaks
25+
26+
## [2.1.4] - October 3, 2021:
27+
* Fix regression in usage of line breaks in body being stripped
28+
29+
## [2.1.3] - October 1, 2021:
30+
* Update minimum versions of dependencies for Flutter 2.5 compatibility
31+
* Extended and fixed support for css shadow
32+
* Fix block tags with explicit whitespace from being stripped
33+
34+
## [2.1.2] - September 2, 2021:
35+
* Allow setting selectionControls with SelectableHtml
36+
* Fix onLinkTap not working with SelectableHtml
37+
* Don't crash when parsing unsupported :hover
38+
* Prevent endless loading when using animated images
39+
40+
## [2.1.1] - July 28, 2021:
41+
* Stable release with all 2.1.1-preview.X changes
42+
43+
## [2.1.1-preview.0] - July 27, 2021:
244
* Improves hr tag support
345
* Fixes a leading whitespace issue
446
* Fixes some crashes with CSS parsing

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ A Flutter widget for rendering HTML and CSS as Flutter widgets.
9898
Add the following to your `pubspec.yaml` file:
9999

100100
dependencies:
101-
flutter_html: ^2.1.1
101+
flutter_html: ^2.2.1
102102

103103
## Currently Supported HTML Tags:
104104
| | | | | | | | | | | |
@@ -185,6 +185,7 @@ Once the above issue is resolved, the aforementioned compromises will go away. C
185185
| `style` | A powerful API that allows you to customize the style that should be used when rendering a specific HTMl tag. |
186186
| `navigationDelegateForIframe` | Allows you to set the `NavigationDelegate` for the `WebView`s of all the iframes rendered by the `Html` widget. |
187187
| `customImageRender` | A powerful API that allows you to fully customize how images are loaded. |
188+
| `selectionControls` | A custom text selection controls that allow you to override default toolbar and build toolbar with custom text selection options. See an [example](https://github.com/justinmc/flutter-text-selection-menu-examples/blob/master/lib/custom_menu_page.dart). |
188189

189190
### Getters:
190191

@@ -268,13 +269,13 @@ Inner links (such as `<a href="#top">Back to the top</a>` will work out of the b
268269

269270
A powerful API that allows you to customize everything when rendering a specific HTML tag. This means you can change the default behaviour or add support for HTML elements that aren't supported natively. You can also make up your own custom tags in your HTML!
270271

271-
`customRender` accepts a `Map<CustomRenderMatcher, CustomRender>`.
272+
`customRender` accepts a `Map<CustomRenderMatcher, CustomRender>`.
272273

273274
`CustomRenderMatcher` is a function that requires a `bool` to be returned. It exposes the `RenderContext` which provides `BuildContext` and access to the HTML tree.
274275

275276
The `CustomRender` class has two constructors: `CustomRender.widget()` and `CustomRender.inlineSpan()`. Both require a `<Widget/InlineSpan> Function(RenderContext, Function())`. The `Function()` argument is a function that will provide you with the element's children when needed.
276277

277-
To use this API, create a matching function and an instance of `CustomRender`.
278+
To use this API, create a matching function and an instance of `CustomRender`.
278279

279280
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.
280281

@@ -390,7 +391,7 @@ Widget html = Html(
390391
391392
CustomRenderMatcher iframeYT() => (context) => context.tree.element?.attributes['src']?.contains("youtube.com/embed") ?? false;
392393
393-
CustomRenderMatcher iframeOther() => (context) => !(context.tree.element?.attributes['src']?.contains("youtube.com/embed")
394+
CustomRenderMatcher iframeOther() => (context) => !(context.tree.element?.attributes['src']?.contains("youtube.com/embed")
394395
?? context.tree.element?.attributes['src'] == null);
395396
396397
CustomRenderMatcher iframeNull() => (context) => context.tree.element?.attributes['src'] == null;
@@ -830,7 +831,8 @@ Widget htmlWidget = Html(
830831
}
831832
},
832833
)),
833-
}
834+
},
835+
tagsList: Html.tags..add('tex'),
834836
);
835837
836838
CustomRenderMatcher texMatcher() => (context) => context.tree.element?.localName == 'tex';

example/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ const htmlData = """
158158
body: SingleChildScrollView(
159159
child: Html(
160160
data: htmlData,
161+
tagsList: Html.tags..addAll(["flutter"]),
161162
//Optional parameters:
162163
style: {
163164
"html": Style(

example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>8.0</string>
24+
<string>9.0</string>
2525
</dict>
2626
</plist>

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ EXTERNAL SOURCES:
2424
:path: ".symlinks/plugins/webview_flutter/ios"
2525

2626
SPEC CHECKSUMS:
27-
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
27+
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
2828
video_player: 9cc823b1d9da7e8427ee591e8438bfbcde500e6e
29-
wakelock: b0843b2479edbf6504d8d262c2959446f35373aa
29+
wakelock: d0fc7c864128eac40eba1617cb5264d9c940b46f
3030
webview_flutter: 9f491a9b5a66f2573946a389b2677987b0ff8c0b
3131

3232
PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d
3333

34-
COCOAPODS: 1.10.1
34+
COCOAPODS: 1.11.2

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
336336
GCC_WARN_UNUSED_FUNCTION = YES;
337337
GCC_WARN_UNUSED_VARIABLE = YES;
338-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
338+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
339339
MTL_ENABLE_DEBUG_INFO = NO;
340340
SDKROOT = iphoneos;
341341
TARGETED_DEVICE_FAMILY = "1,2";
@@ -414,7 +414,7 @@
414414
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
415415
GCC_WARN_UNUSED_FUNCTION = YES;
416416
GCC_WARN_UNUSED_VARIABLE = YES;
417-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
417+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
418418
MTL_ENABLE_DEBUG_INFO = YES;
419419
ONLY_ACTIVE_ARCH = YES;
420420
SDKROOT = iphoneos;
@@ -463,7 +463,7 @@
463463
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
464464
GCC_WARN_UNUSED_FUNCTION = YES;
465465
GCC_WARN_UNUSED_VARIABLE = YES;
466-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
466+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
467467
MTL_ENABLE_DEBUG_INFO = NO;
468468
SDKROOT = iphoneos;
469469
TARGETED_DEVICE_FAMILY = "1,2";

example/lib/generated_plugin_registrant.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Generated file. Do not edit.
33
//
44

5+
// ignore_for_file: directives_ordering
56
// ignore_for_file: lines_longer_than_80_chars
67

78
import 'package:video_player_web/video_player_web.dart';

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ class _MyHomePageState extends State<MyHomePage> {
251251
body: SingleChildScrollView(
252252
child: Html(
253253
data: htmlData,
254+
tagsList: Html.tags..addAll(["bird", "flutter"]),
254255
style: {
255256
"table": Style(
256257
backgroundColor: Color.fromARGB(0x50, 0xee, 0xee, 0xee),

lib/flutter_html.dart

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:flutter_html/image_render.dart';
88
import 'package:flutter_html/src/html_elements.dart';
99
import 'package:flutter_html/style.dart';
1010
import 'package:html/dom.dart' as dom;
11-
import 'package:webview_flutter/webview_flutter.dart';
11+
import 'package:flutter_html/src/navigation_delegate.dart';
1212

1313
//export render context api
1414
export 'package:flutter_html/html_parser.dart';
@@ -25,6 +25,7 @@ export 'package:flutter_html/src/interactable_element.dart';
2525
export 'package:flutter_html/src/layout_element.dart';
2626
export 'package:flutter_html/src/replaced_element.dart';
2727
export 'package:flutter_html/src/styled_element.dart';
28+
export 'package:flutter_html/src/navigation_delegate.dart';
2829
//export style api
2930
export 'package:flutter_html/style.dart';
3031

@@ -50,7 +51,7 @@ class Html extends StatelessWidget {
5051
///
5152
/// **onImageTap** This is called whenever an image is tapped.
5253
///
53-
/// **tagsList** Tag names in this array will be the only tags rendered. By default all tags are rendered.
54+
/// **tagsList** Tag names in this array will be the only tags rendered. By default all supported HTML tags are rendered.
5455
///
5556
/// **style** Pass in the style information for the Html here.
5657
/// See [its wiki page](https://github.com/Sub6Resources/flutter_html/wiki/Style) for more info.
@@ -133,7 +134,7 @@ class Html extends StatelessWidget {
133134
/// A function that defines what to do when an image is tapped
134135
final OnTap? onImageTap;
135136

136-
/// A list of HTML tags that defines what elements are not rendered
137+
/// A list of HTML tags that are the only tags that are rendered. By default, this list is empty and all supported HTML tags are rendered.
137138
final List<String> tagsList;
138139

139140
/// Either return a custom widget for specific node types or return null to
@@ -202,7 +203,7 @@ class SelectableHtml extends StatelessWidget {
202203
/// **onAnchorTap** This function is called whenever an anchor (#anchor-id)
203204
/// is tapped.
204205
///
205-
/// **tagsList** Tag names in this array will be the only tags rendered. By default all tags that support selectable content are rendered.
206+
/// **tagsList** Tag names in this array will be the only tags rendered. By default, all tags that support selectable content are rendered.
206207
///
207208
/// **style** Pass in the style information for the Html here.
208209
/// See [its wiki page](https://github.com/Sub6Resources/flutter_html/wiki/Style) for more info.
@@ -222,6 +223,7 @@ class SelectableHtml extends StatelessWidget {
222223
223224
SelectableHtml({
224225
Key? key,
226+
GlobalKey? anchorKey,
225227
required this.data,
226228
this.onLinkTap,
227229
this.onAnchorTap,
@@ -230,11 +232,16 @@ class SelectableHtml extends StatelessWidget {
230232
this.style = const {},
231233
this.customRenders = const {},
232234
this.tagsList = const [],
235+
this.selectionControls,
236+
this.scrollPhysics,
233237
}) : document = null,
238+
assert(data != null),
239+
_anchorKey = anchorKey ?? GlobalKey(),
234240
super(key: key);
235241

236242
SelectableHtml.fromDom({
237243
Key? key,
244+
GlobalKey? anchorKey,
238245
required this.document,
239246
this.onLinkTap,
240247
this.onAnchorTap,
@@ -243,9 +250,16 @@ class SelectableHtml extends StatelessWidget {
243250
this.style = const {},
244251
this.customRenders = const {},
245252
this.tagsList = const [],
253+
this.selectionControls,
254+
this.scrollPhysics,
246255
}) : data = null,
256+
assert(document != null),
257+
_anchorKey = anchorKey ?? GlobalKey(),
247258
super(key: key);
248259

260+
/// A unique key for this Html widget to ensure uniqueness of anchors
261+
final GlobalKey _anchorKey;
262+
249263
/// The HTML data passed to the widget as a String
250264
final String? data;
251265

@@ -266,12 +280,19 @@ class SelectableHtml extends StatelessWidget {
266280
/// flexible
267281
final bool shrinkWrap;
268282

269-
/// A list of HTML tags that defines what elements are not rendered
283+
/// A list of HTML tags that are the only tags that are rendered. By default, this list is empty and all supported HTML tags are rendered.
270284
final List<String> tagsList;
271285

272286
/// An API that allows you to override the default style for any HTML element
273287
final Map<String, Style> style;
274288

289+
/// Custom Selection controls allows you to override default toolbar and build custom toolbar
290+
/// options
291+
final TextSelectionControls? selectionControls;
292+
293+
/// Allows you to override the default scrollPhysics for [SelectableText.rich]
294+
final ScrollPhysics? scrollPhysics;
295+
275296
/// Either return a custom widget for specific node types or return null to
276297
/// fallback to the default rendering.
277298
final Map<CustomRenderMatcher, SelectableCustomRender> customRenders;
@@ -286,7 +307,7 @@ class SelectableHtml extends StatelessWidget {
286307
return Container(
287308
width: width,
288309
child: HtmlParser(
289-
key: null,
310+
key: _anchorKey,
290311
htmlData: doc,
291312
onLinkTap: onLinkTap,
292313
onAnchorTap: onAnchorTap,
@@ -303,6 +324,8 @@ class SelectableHtml extends StatelessWidget {
303324
imageRenders: defaultImageRenders,
304325
tagsList: tagsList.isEmpty ? SelectableHtml.tags : tagsList,
305326
navigationDelegateForIframe: null,
327+
selectionControls: selectionControls,
328+
scrollPhysics: scrollPhysics,
306329
),
307330
);
308331
}

0 commit comments

Comments
 (0)