Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate CustomRender to HtmlExtension #1176

Merged
merged 31 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
505ffa5
Start process of migrating customRender to extension
Sub6Resources Oct 21, 2022
c5ee0bd
Create initial extension and extension context classes
Sub6Resources Oct 22, 2022
6c9b870
Implement Extension mechanism throughout core library
Sub6Resources May 8, 2023
d1a6b49
Refactor flutter_html_math
Sub6Resources May 8, 2023
b60e6d6
Refactor flutter_html_audio and flutter_html_video
Sub6Resources May 8, 2023
f076647
Refactor flutter_html_iframe
Sub6Resources May 8, 2023
b689c31
Refactor flutter_html_table
Sub6Resources May 8, 2023
bbad55d
Refactor flutter_html_svg and run flutter format
Sub6Resources May 9, 2023
5835be0
Upgrade melos
Sub6Resources May 9, 2023
fbd6646
Update CircleCI config to remove deprecated command
Sub6Resources May 9, 2023
94c452b
Fix typo
Sub6Resources May 9, 2023
9e1fd76
Add missing onDispose tie-in
Sub6Resources May 9, 2023
6638d16
Fix issue with flutter_html_svg.dart
Sub6Resources May 9, 2023
c1697dd
Add ImageExtension
Sub6Resources May 12, 2023
330ca63
Undo unintentional CSSBoxRenderer change
Sub6Resources May 12, 2023
7ea3667
chore(release): publish packages
Sub6Resources May 12, 2023
32fb25b
Update changelog for new version
Sub6Resources May 12, 2023
558ce4a
Add OnImageTapExtension and update documentation
Sub6Resources May 12, 2023
c52f5db
Revert collection version
Sub6Resources May 12, 2023
6625f6d
Update example and remove customRenders fully
Sub6Resources May 12, 2023
1266b2f
Reformat code. Whoops
Sub6Resources May 12, 2023
93db3af
Fix outdated documentation
Sub6Resources May 12, 2023
2c61da1
Change Extension to HtmlExtension
Sub6Resources May 13, 2023
f5d2a8f
Update constraints for dart 3
Sub6Resources May 13, 2023
0201898
Add topics to pubspec
Sub6Resources May 13, 2023
935cefa
Add topics to all pubspec files
Sub6Resources May 13, 2023
667711a
Remove assertion on onlyRenderTheseTags and doNotRenderTheseTags
Sub6Resources May 13, 2023
50b0ec7
Fix bug with ImageExtension and upgrade a couple dependencies for Dar…
Sub6Resources May 13, 2023
af02d45
Loosen constraint on flutter_math_fork package
Sub6Resources May 13, 2023
bcf87a9
Update screenshots in README and pubspec
Sub6Resources May 13, 2023
3ed46cf
Move screenshots
Sub6Resources May 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
command: melos run analyze
- run:
name: Check That Flutter Code is Formatted Correctly
command: flutter format -o none --set-exit-if-changed .
command: dart format -o none --set-exit-if-changed .
Binary file added .github/flutter_html_screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,6 @@ modules.xml

packages/**/pubspec_overrides.yaml
./pubspec_overrides.yaml
/example/pubspec_overrides.yaml
/example/pubspec_overrides.yaml

coverage/
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Change Log


#### 3.0.0-beta.1 - *May 2023*

- Several Breaking Changes. See the [migration guide](https://github.com/Sub6Resources/flutter_html/wiki/Migration-Guides#300)

- **FIX**: Aspect ratio exception when height is 0 ([#1222](https://github.com/sub6resources/flutter_html/issues/1222)). ([ed75f8fe](https://github.com/sub6resources/flutter_html/commit/ed75f8fef779e920ecc1f27719a4150a29e3ebee))
- **FIX**: Fix issue with font scaling introduced in 3.0.0-alpha.6 ([#1173](https://github.com/sub6resources/flutter_html/issues/1173)). ([c75e0dfb](https://github.com/sub6resources/flutter_html/commit/c75e0dfb1be6cb79748f719487043d12bc330c60))
- **FIX**: Fix various issues with list rendering. ([520ff3c3](https://github.com/sub6resources/flutter_html/commit/520ff3c326d5dc8f5a601022c2a32d58e2e83cbb))
- **FIX**: Apply margins to <table> properly. ([7581ea79](https://github.com/sub6resources/flutter_html/commit/7581ea798744b2830affaaf75bbdff016b03f7af))
- **FIX**: Use enum instead of const int internally in length.dart. ([9dc7f08c](https://github.com/sub6resources/flutter_html/commit/9dc7f08ca238ff6a93314be5de716ad4e3baebb8))
- **FIX**: Change CSSBoxWidget to CssBoxWidget. ([a62449a7](https://github.com/sub6resources/flutter_html/commit/a62449a77c18701a0faf8ffd650f9c535b2d006c))
- **FEAT**: Support mmultiscripts. ([#1175](https://github.com/sub6resources/flutter_html/issues/1175)). ([a999a300](https://github.com/sub6resources/flutter_html/commit/a999a30027eff0aabb2825ffdbe383f9affab7f6))
- **FEAT**: Support mfenced. ([#1174](https://github.com/sub6resources/flutter_html/issues/1174)). ([9ca23084](https://github.com/sub6resources/flutter_html/commit/9ca230848beb15332f96294083ed4989831130d7))
- **FEAT**: Upgrade list-style-type to CSS3. ([deb726ae](https://github.com/sub6resources/flutter_html/commit/deb726ae2776f45305026c0aa081d4a5b5a1c71d))
- **FEAT**: Support mtable, mtd, mtr for draw matrix. ([#1164](https://github.com/sub6resources/flutter_html/issues/1164)). ([e99e2cc1](https://github.com/sub6resources/flutter_html/commit/e99e2cc1553ab17b4ceff08f784e99283b28dff4))

## 3.0.0-alpha.6 - *September 2022*

- **FIX** #731 Resolve newline `<br>` issue
Expand Down
728 changes: 140 additions & 588 deletions README.md

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions example/lib/generated_plugin_registrant.dart

This file was deleted.

146 changes: 58 additions & 88 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ const htmlData = r"""
</p>
<table>
<colgroup>
<col width="50%" />
<col span="2" width="25%" />
<col width="200" />
<col span="2" width="150" />
</colgroup>
<thead>
<tr><th>One</th><th>Two</th><th>Three</th></tr>
</thead>
<tbody>
<tr>
<td rowspan='2'>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan</td><td>Data</td><td>Data</td>
<td rowspan='2'>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan<br>Rowspan</td><td>Data</td><td>Data</td>
</tr>
<tr>
<td colspan="2"><img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' /></td>
<td colspan="2"><img width="175" alt='xkcd' src='https://imgs.xkcd.com/comics/commemorative_plaque.png' /></td>
</tr>
</tbody>
<tfoot>
Expand Down Expand Up @@ -135,7 +135,7 @@ const htmlData = r"""
</p>
<h3>Image support:</h3>
<h3>Network png</h3>
<img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' />
<img width="200" alt='xkcd' src='https://imgs.xkcd.com/comics/commemorative_plaque.png' />
<h3>Network svg</h3>
<img src='https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/android.svg' />
<h3>Local asset png</h3>
Expand All @@ -154,7 +154,7 @@ const htmlData = r"""
<img alt='No source' />
<img alt='Empty source' src='' />
<h3>Broken network image</h3>
<img alt='Broken image' src='https://www.notgoogle.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' />
<img alt='Broken image' src='https://www.example.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' />
<h3>MathML Support:</h3>
<math>
<mrow>
Expand Down Expand Up @@ -203,7 +203,7 @@ const htmlData = r"""
<mn>2</mn>
</msup>
<mo>&sdot;</mo>
<mi>&dd;</mi><mi>x</mi>
<mi>d</mi><mi>x</mi>
<mo>=</mo>
<mo>[</mo>
<mfrac>
Expand Down Expand Up @@ -232,6 +232,7 @@ const htmlData = r"""
<mi>3</mi>
</mfrac>
</math>
<br />
<math>
<msup>
<mo>sin</mo>
Expand Down Expand Up @@ -280,90 +281,68 @@ class MyHomePageState extends State<MyHomePage> {
"table": Style(
backgroundColor: const Color.fromARGB(0x50, 0xee, 0xee, 0xee),
),
"tr": Style(
border: const Border(bottom: BorderSide(color: Colors.grey)),
),
"th": Style(
padding: const EdgeInsets.all(6),
backgroundColor: Colors.grey,
),
"td": Style(
padding: const EdgeInsets.all(6),
alignment: Alignment.topLeft,
border: const Border(bottom: BorderSide(color: Colors.grey)),
),
'h5': Style(maxLines: 2, textOverflow: TextOverflow.ellipsis),
},
tagsList: Html.tags..addAll(['tex', 'bird', 'flutter']),
customRenders: {
tagMatcher("tex"): CustomRender.widget(
widget: (context, buildChildren) => Math.tex(
context.tree.element?.innerHtml ?? '',
mathStyle: MathStyle.display,
textStyle: context.style.generateTextStyle(),
onErrorFallback: (FlutterMathException e) {
return Text(e.message);
},
)),
tagMatcher("bird"): CustomRender.inlineSpan(
inlineSpan: (context, buildChildren) =>
const TextSpan(text: "🐦")),
tagMatcher("flutter"): CustomRender.widget(
widget: (context, buildChildren) => FlutterLogo(
style: (context.tree.element!.attributes['horizontal'] !=
null)
? FlutterLogoStyle.horizontal
: FlutterLogoStyle.markOnly,
textColor: context.style.color!,
size: context.style.fontSize!.value * 5,
)),
tagMatcher("table"): CustomRender.widget(
widget: (context, buildChildren) => SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: tableRender
.call()
.widget!
.call(context, buildChildren),
)),
audioMatcher(): audioRender(),
iframeMatcher(): iframeRender(),
mathMatcher():
mathRender(onMathError: (error, exception, exceptionWithType) {
debugPrint(exception);
return Text(exception);
}),
svgTagMatcher(): svgTagRender(),
svgDataUriMatcher(): svgDataImageRender(),
svgAssetUriMatcher(): svgAssetImageRender(),
svgNetworkSourceMatcher(): svgNetworkImageRender(),
networkSourceMatcher(domains: ["flutter.dev"]):
CustomRender.widget(widget: (context, buildChildren) {
return const FlutterLogo(size: 36);
}),
networkSourceMatcher(domains: ["mydomain.com"]): networkImageRender(
headers: {"Custom-Header": "some-value"},
altWidget: (alt) => Text(alt ?? ""),
loadingWidget: () => const Text("Loading..."),
'flutter': Style(
display: Display.block,
fontSize: FontSize(5, Unit.em),
),
// On relative paths starting with /wiki, prefix with a base url
(context) =>
context.tree.element?.attributes["src"] != null &&
context.tree.element!.attributes["src"]!
.startsWith("/wiki"): networkImageRender(
mapUrl: (url) => "https://upload.wikimedia.org${url!}"),
// Custom placeholder image for broken links
networkSourceMatcher():
networkImageRender(altWidget: (_) => const FlutterLogo()),
videoMatcher(): videoRender(),
},
onLinkTap: (url, _, __, ___) {
extensions: [
TagExtension(
tagsToExtend: {"tex"},
builder: (context) => Math.tex(
context.innerHtml,
mathStyle: MathStyle.display,
textStyle: context.styledElement?.style.generateTextStyle(),
onErrorFallback: (FlutterMathException e) {
return Text(e.message);
},
),
),
TagExtension.inline(
tagsToExtend: {"bird"},
child: const TextSpan(text: "🐦"),
),
TagExtension(
tagsToExtend: {"flutter"},
builder: (context) => FlutterLogo(
style: context.attributes['horizontal'] != null
? FlutterLogoStyle.horizontal
: FlutterLogoStyle.markOnly,
textColor: context.styledElement!.style.color!,
size: context.styledElement!.style.fontSize!.value,
),
),
ImageExtension(
handleAssetImages: false,
handleDataImages: false,
networkDomains: {"flutter.dev"},
child: const FlutterLogo(size: 36),
),
ImageExtension(
handleAssetImages: false,
handleDataImages: false,
networkDomains: {"mydomain.com"},
networkHeaders: {"Custom-Header": "some-value"},
),
const MathHtmlExtension(),
const AudioHtmlExtension(),
const VideoHtmlExtension(),
const IframeHtmlExtension(),
const TableHtmlExtension(),
const SvgHtmlExtension(),
],
onLinkTap: (url, _, __) {
debugPrint("Opening $url...");
},
onImageTap: (src, _, __, ___) {
debugPrint(src);
},
onImageError: (exception, stackTrace) {
debugPrint(exception.toString());
},
onCssParseError: (css, messages) {
debugPrint("css that errored: $css");
debugPrint("error messages:");
Expand All @@ -377,12 +356,3 @@ class MyHomePageState extends State<MyHomePage> {
);
}
}

CustomRenderMatcher texMatcher() =>
(context) => context.tree.element?.localName == 'tex';

CustomRenderMatcher birdMatcher() =>
(context) => context.tree.element?.localName == 'bird';

CustomRenderMatcher flutterMatcher() =>
(context) => context.tree.element?.localName == 'flutter';
Loading