diff --git a/demo_app/lib/screens/home.dart b/demo_app/lib/screens/home.dart
index a403d2ee0..ff7d428c1 100644
--- a/demo_app/lib/screens/home.dart
+++ b/demo_app/lib/screens/home.dart
@@ -12,6 +12,7 @@ import 'huge_html.dart';
import 'iframe.dart';
import 'img.dart';
import 'img_file.dart';
+import 'math.dart';
import 'photo_view.dart';
import 'smilie.dart';
import 'video.dart';
@@ -25,6 +26,7 @@ class HomeScreen extends StatelessWidget {
'Iframe': () => const IframeScreen(),
'Images': () => const ImgScreen(),
'Image (file://)': () => const ImgFileScreen(),
+ 'Math': () => const MathScreen(),
'Video': () => const VideoScreen(),
'customStylesBuilder': () => const CustomStylesBuilderScreen(),
'customWidgetBuilder': () => const CustomWidgetBuilderScreen(),
diff --git a/demo_app/lib/screens/math.dart b/demo_app/lib/screens/math.dart
new file mode 100644
index 000000000..131d12443
--- /dev/null
+++ b/demo_app/lib/screens/math.dart
@@ -0,0 +1,22 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
+import 'package:fwfh_math/fwfh_math.dart';
+
+class MathScreen extends StatelessWidget {
+ const MathScreen({Key key}) : super(key: key);
+
+ @override
+ Widget build(BuildContext context) => Scaffold(
+ appBar: AppBar(
+ title: const Text('MathFactory Demo'),
+ ),
+ body: Center(
+ child: HtmlWidget(
+ r'Check this out: ',
+ factoryBuilder: () => MyWidgetFactory(),
+ ),
+ ),
+ );
+}
+
+class MyWidgetFactory extends WidgetFactory with MathFactory {}
diff --git a/demo_app/pubspec.yaml b/demo_app/pubspec.yaml
index dd44081ec..5612efd6e 100644
--- a/demo_app/pubspec.yaml
+++ b/demo_app/pubspec.yaml
@@ -12,6 +12,7 @@ dependencies:
flutter_widget_from_html: any
flutter_widget_from_html_core: any
fwfh_chewie: any
+ fwfh_math: any
fwfh_url_launcher: any
fwfh_webview: any
html: any
@@ -35,6 +36,8 @@ dependency_overrides:
path: ../packages/fwfh_chewie
fwfh_just_audio:
path: ../packages/fwfh_just_audio
+ fwfh_math:
+ path: ../packages/fwfh_math
fwfh_svg:
path: ../packages/fwfh_svg
fwfh_url_launcher:
diff --git a/packages/fwfh_math/CHANGELOG.md b/packages/fwfh_math/CHANGELOG.md
new file mode 100644
index 000000000..b20293ff5
--- /dev/null
+++ b/packages/fwfh_math/CHANGELOG.md
@@ -0,0 +1,3 @@
+## 0.6.0-rc.2021022601
+
+- First release
diff --git a/packages/fwfh_math/LICENSE b/packages/fwfh_math/LICENSE
new file mode 100644
index 000000000..a8b1cb2d2
--- /dev/null
+++ b/packages/fwfh_math/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2020 Dao Hoang Son
+
+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.
diff --git a/packages/fwfh_math/README.md b/packages/fwfh_math/README.md
new file mode 100644
index 000000000..7be72218c
--- /dev/null
+++ b/packages/fwfh_math/README.md
@@ -0,0 +1,39 @@
+# MathFactory
+
+
+[](https://codecov.io/gh/daohoangson/flutter_widget_from_html)
+[](https://pub.dev/packages/fwfh_math)
+
+WidgetFactory extension to render math equation with [flutter_math](https://pub.dev/packages/flutter_math) package.
+This is a companion add-on for [flutter_widget_from_html_core](https://pub.dev/packages/flutter_widget_from_html_core) package.
+
+## Getting Started
+
+Add this to your app's `pubspec.yaml` file:
+
+```yaml
+dependencies:
+ flutter_widget_from_html_core: any
+ fwfh_math: ^0.6.0
+```
+
+## Usage
+
+Then use `HtmlWidget` with a custom factory:
+
+```dart
+import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
+import 'package:fwfh_math/fwfh_math.dart';
+
+// ...
+
+HtmlWidget(
+ html,
+ factoryBuilder: () => MyWidgetFactory(),
+)
+
+// ...
+
+class MyWidgetFactory extends WidgetFactory with MathFactory {
+}
+```
diff --git a/packages/fwfh_math/analysis_options.yaml b/packages/fwfh_math/analysis_options.yaml
new file mode 100644
index 000000000..108d1058a
--- /dev/null
+++ b/packages/fwfh_math/analysis_options.yaml
@@ -0,0 +1 @@
+include: package:pedantic/analysis_options.yaml
diff --git a/packages/fwfh_math/example/main.dart b/packages/fwfh_math/example/main.dart
new file mode 100644
index 000000000..04af7ea67
--- /dev/null
+++ b/packages/fwfh_math/example/main.dart
@@ -0,0 +1,27 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
+import 'package:fwfh_math/fwfh_math.dart';
+
+void main() => runApp(MyApp());
+
+class MyApp extends StatelessWidget {
+ @override
+ Widget build(BuildContext context) {
+ return MaterialApp(
+ title: 'fwfh_math',
+ home: Scaffold(
+ appBar: AppBar(
+ title: Text('MathFactory Demo'),
+ ),
+ body: Center(
+ child: HtmlWidget(
+ r'Check this out: ',
+ factoryBuilder: () => MyWidgetFactory(),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+class MyWidgetFactory extends WidgetFactory with MathFactory {}
diff --git a/packages/fwfh_math/lib/fwfh_math.dart b/packages/fwfh_math/lib/fwfh_math.dart
new file mode 100644
index 000000000..7a81f4497
--- /dev/null
+++ b/packages/fwfh_math/lib/fwfh_math.dart
@@ -0,0 +1 @@
+export 'src/math_factory.dart';
diff --git a/packages/fwfh_math/lib/src/math_factory.dart b/packages/fwfh_math/lib/src/math_factory.dart
new file mode 100644
index 000000000..bd34feb02
--- /dev/null
+++ b/packages/fwfh_math/lib/src/math_factory.dart
@@ -0,0 +1,19 @@
+import 'package:flutter_math_fork/flutter_math.dart';
+import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
+
+/// A mixin that can render math equation with `flutter_math` package.
+mixin MathFactory on WidgetFactory {
+ @override
+ void parse(BuildMetadata meta) {
+ if (meta.element.localName == 'math') {
+ meta.register(BuildOp(
+ onTree: (meta, tree) {
+ tree.replaceWith(
+ WidgetBit.inline(tree, Math.tex(meta.element.innerHtml)));
+ },
+ ));
+ }
+
+ super.parse(meta);
+ }
+}
diff --git a/packages/fwfh_math/pubspec.yaml b/packages/fwfh_math/pubspec.yaml
new file mode 100644
index 000000000..980c1ac95
--- /dev/null
+++ b/packages/fwfh_math/pubspec.yaml
@@ -0,0 +1,27 @@
+name: fwfh_math
+version: 0.6.0-rc.2021022601
+description: WidgetFactory extension to render math equation with flutter_math package.
+homepage: https://github.com/daohoangson/flutter_widget_from_html
+publish_to: none
+
+environment:
+ flutter: ">=2.0.0"
+ sdk: ">=2.12.0 <3.0.0"
+
+dependencies:
+ flutter:
+ sdk: flutter
+ flutter_widget_from_html_core: ^0.6.0-0
+ flutter_math_fork:
+ git:
+ url: https://github.com/simpleclub-extended/flutter_math_fork.git
+ ref: 100a5783ac7aa9dafb70273766dc275dab7f5517
+
+dependency_overrides:
+ flutter_widget_from_html_core:
+ path: ../core
+
+dev_dependencies:
+ flutter_test:
+ sdk: flutter
+ pedantic: any