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

Version 1.0.0 #122

Merged
merged 69 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
9ee86ee
Add initial structure for new parser
Sub6Resources Mar 13, 2019
6a785d3
WIP: Lexer
Sub6Resources Mar 13, 2019
11ed881
Initial changes for new parser
Sub6Resources May 13, 2019
a7dc12d
Merge branch master
Sub6Resources May 14, 2019
c05a441
Update new parser with more tag support
Sub6Resources May 14, 2019
1157384
Add new elements to new parser
Sub6Resources May 15, 2019
57d666a
Add even more html elements to new parser and more tests
Sub6Resources May 15, 2019
6e4b46f
Merge upstream master
Sub6Resources Jun 7, 2019
ece0fca
Fix lots o' formatting issues
Sub6Resources Jun 9, 2019
7bbd22f
Move Style to new file and prep for css parsing. Update README.md
Sub6Resources Jun 14, 2019
17cfb62
Add codecov and prepare for css parsing
Sub6Resources Jun 18, 2019
2f6d4b5
Up the flutter version for circleci
Sub6Resources Jun 18, 2019
f392917
Start moving from class-based styling to Style-based styling
Sub6Resources Jun 18, 2019
cce767f
Change BlockElement to StyledElement with Display.BLOCK and add suppo…
Sub6Resources Jun 20, 2019
84d00e0
Replaced element instead of Content element and move more stuff to St…
Sub6Resources Jul 17, 2019
35400c8
Create full example project and fix some issues
Sub6Resources Sep 20, 2019
cc1d795
Add .metadata
Sub6Resources Sep 20, 2019
5bc1f75
Fix example
Sub6Resources Sep 20, 2019
b30d166
Merge master into new-parser
Sub6Resources Sep 20, 2019
935dcc4
Temporarily useRichText to test tests
Sub6Resources Sep 20, 2019
c34af85
Undo golden test useRichText
Sub6Resources Sep 20, 2019
aca4bc3
Add all replaced elements
Sub6Resources Sep 30, 2019
ce7d979
Remove Block and block_element.dart in favor of Style
Sub6Resources Sep 30, 2019
8b03852
Refactor lists
Sub6Resources Oct 1, 2019
49fcc93
Fix inline whitespace processing
Sub6Resources Oct 2, 2019
9d6e597
Fix issues with lists and cascading styles
Sub6Resources Oct 3, 2019
d86fc77
WIP: Tables
Sub6Resources Oct 17, 2019
be196a8
feat table and colgroup
dotneet Oct 21, 2019
cb2c2bf
support ruby element.
dotneet Oct 23, 2019
ba8301c
fix: Crash when a tr tag includes text node.
dotneet Oct 25, 2019
48bbeb9
improve table style
dotneet Oct 25, 2019
2f0090e
Migrate example to androidx
Sub6Resources Dec 12, 2019
1086f15
Merge pull request #176 from dotneet/table
Sub6Resources Dec 12, 2019
63f7bb0
Revert "WIP: Tables"
Sub6Resources Dec 12, 2019
2931bce
Merge branch 'new-parser' of https://github.com/Sub6Resources/flutter…
Sub6Resources Dec 12, 2019
f52af25
Merge pull request #178 from dotneet/ruby
Sub6Resources Dec 12, 2019
02084fe
Add support for both sub and sup as well as add the css property
Sub6Resources Dec 14, 2019
31359b7
Merge pull request #197 from Sub6Resources/sub-sup
Sub6Resources Dec 14, 2019
f3ad232
Add support for borders, width, and height on tables
Sub6Resources Dec 14, 2019
b6987e3
Merge pull request #198 from Sub6Resources/table-fixes
Sub6Resources Dec 14, 2019
bed7cc6
Add support for asset images to the new parser
Sub6Resources Dec 14, 2019
b4e32a8
Merge branch 'master' into new-parser
Sub6Resources Dec 14, 2019
2a6e768
Update pubspec.lock
Sub6Resources Dec 14, 2019
85a2840
Fix styling issue with lists
Sub6Resources Dec 16, 2019
135316f
Re-add support for onImageError and onImageTap and fix issues with im…
Sub6Resources Dec 17, 2019
5be653d
Add shrinkWrap property, fix small link-image issue and style alignme…
Sub6Resources Dec 18, 2019
0c68d36
Update documentation
Sub6Resources Dec 21, 2019
b93e79b
Format files
Sub6Resources Dec 21, 2019
5d12366
Update customRender
Sub6Resources Dec 22, 2019
b9fc0cb
Update description
Sub6Resources Dec 27, 2019
a34d3bf
Update changelong and some last minute fixes
Sub6Resources Dec 27, 2019
753db68
Update CHANGELOG and remove author from pubspec
Sub6Resources Dec 27, 2019
3badf23
Fixes #217
ngaurav Feb 4, 2020
c68c59d
Add additional CSS styles
Sub6Resources Feb 8, 2020
b5046d9
Merge pull request #225 from ngaurav/new-parser
Sub6Resources Feb 8, 2020
b55c0b1
Merge pull request #1 from Sub6Resources/new-parser
ngaurav Feb 21, 2020
a3f2275
rt and ruby distance
JeskTop Mar 4, 2020
f478f18
Package upgrade
JEuler Mar 13, 2020
2d15055
Fixed #218
ngaurav Apr 14, 2020
4f2ef09
Merge pull request #244 from JEuler/packages-upgrade
Sub6Resources Apr 15, 2020
d1d5bd8
Merge pull request #239 from JeskTop/rt-distance
Sub6Resources Apr 15, 2020
45838a0
Merge pull request #261 from ngaurav/ngaurav-patch-1
Sub6Resources Apr 15, 2020
77bd460
Update packages again
Sub6Resources Apr 15, 2020
4ddeb1e
Prepare for 1.0.0 release
Sub6Resources May 11, 2020
4a512dc
Update goldens and fix 'q' tag
Sub6Resources May 11, 2020
cf0bb63
Disable golden tests for now
Sub6Resources May 11, 2020
1686b19
Temporarily replace golden tests with regular test
Sub6Resources May 11, 2020
58464dc
flutter format
ryan-berger May 11, 2020
0980df6
Merge branch 'master' into new-parser
ryan-berger May 11, 2020
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
8 changes: 6 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
version: 2
version: 2.1
orbs:
codecov: codecov/codecov@1.0.2
jobs:
build:
docker:
- image: cirrusci/flutter
steps:
- checkout
- run: flutter --version
- run: flutter test
- run: flutter test --coverage
- codecov/upload:
file: coverage/lcov.info
Binary file modified .github/flutter_html_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/flutter_html_screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/flutter_html_screenshot3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ modules.xml
# End of https://www.gitignore.io/api/flutter,jetbrains+all

**/.flutter-plugins-dependencies

**/flutter_export_environment.sh
10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 20e59316b8b8474554b38493b8ca888794b0234a
channel: stable

project_type: package
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# [1.0.0]
* BREAKING CHANGES (see the [Migration Guide](https://github.com/Sub6Resources/flutter_html/wiki/1.0.0-Migration-Guide) for a full overview of breaking changes.):
* The default parser has been completely rewritten and the RichText parser has been removed.
* `useRichText` no longer is necessary (The new parser uses RichText under the hood)
* `customRender` now works for the default parser.
* Adds support for `<audio>`, `<video>`, `<iframe>`, `<svg>`, `<ruby>`, `<rt>`, `<rp>`, `<sub>`, and `<sup>`
* Adds support for over 20 CSS attributes when using the `style` parameter.
* Fixes many many issues (see the list at [#122](https://github.com/Sub6Resources/flutter_html/pull/122))
* The following parameters of `Html` have been removed and should no longer be used (see the migration guide):
* `useRichText`
* `padding`
* `backgroundColor`
* `defaultTextStyle`
* `renderNewlines`
* `customEdgeInsets`
* `customTextStyle`
* `blockSpacing`
* `customTextAlign`
* `linkStyle`
* `imageProperties`
* `showImages`
* The default text style now matches the app's Material `TextTheme.bodyText2` (Fixes [#18](https://github.com/Sub6Resources/flutter_html/issues/18)).
* Requires Flutter v1.17.0 or greater
* Fixed quite a few issues with `img`
* Added a fancy new `style` attribute (this should be used in place of the deprecated styling parameters).

## [1.0.0-pre.1] - December 27, 2019

* For a list of pre-release changes, including several BREAKING CHANGES, see release notes for 1.0.0 above.

## [0.11.1] - December 14, 2019:

* Add support for `AssetImage`s using the `asset:` prefix ([#162](https://github.com/Sub6Resources/flutter_html/pull/162)).
Expand Down Expand Up @@ -42,7 +72,6 @@
* Add support for `address` tag in `RichText` parser.

## [0.9.7] - May 13, 2019:

* Added onImageError callback
* Added custom textstyle and edgeinsets callback ([#72](https://github.com/Sub6Resources/flutter_html/pull/72))
* Update dependency versions ([#84](https://github.com/Sub6Resources/flutter_html/issues/84))
Expand Down
117 changes: 35 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,119 +1,72 @@
# flutter_html
[![pub package](https://img.shields.io/pub/v/flutter_html.svg)](https://pub.dev/packages/flutter_html)
[![codecov](https://codecov.io/gh/Sub6Resources/flutter_html/branch/master/graph/badge.svg)](https://codecov.io/gh/Sub6Resources/flutter_html)
[![CircleCI](https://circleci.com/gh/Sub6Resources/flutter_html.svg?style=svg)](https://circleci.com/gh/Sub6Resources/flutter_html)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/Sub6Resources/flutter_html/blob/master/LICENSE)

> **Note: 1.0.0-pre.1 has been released! See the [Migration Guide](https://github.com/Sub6Resources/flutter_html/wiki/1.0.0-Migration-Guide) if you'd like to take advantage of all the new features of 1.0.0! Also, check out the [Prerelease Changelog](https://github.com/Sub6Resources/flutter_html/blob/new-parser/PRE_CHANGELOG.md).** Version 1.0.0 is currently on the `new-parser` branch. This README will be updated when 1.0.0 is merged into the master branch.

A Flutter widget for rendering static html tags as Flutter widgets. (Will render over 70 different html tags!)
A Flutter widget for rendering html and css as Flutter widgets.

<img alt="A Screenshot of flutter_html" src=".github/flutter_html_screenshot.png" width="300"/>
<img alt="Another Screenshot of flutter_html" src=".github/flutter_html_screenshot2.png" width="300"/>
<img alt="Yet another Screenshot of flutter_html" src=".github/flutter_html_screenshot3.png" width="300"/>

## Installing:

Add the following to your `pubspec.yaml` file:

dependencies:
flutter_html: ^0.11.1
flutter_html: ^1.0.0-pre.1

## Currently Supported HTML Tags:
`a`, `abbr`, `acronym`, `address`, `article`, `aside`, `b`, `bdi`, `bdo`, `big`, `blockquote`, `body`, `br`, `caption`, `cite`, `code`, `data`, `dd`, `del`, `dfn`, `div`, `dl`, `dt`, `em`, `figcaption`, `figure`, `footer`, `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `header`, `hr`, `i`, `img`, `ins`, `kbd`, `li`, `main`, `mark`, `nav`, `noscript`, `ol`, `p`, `pre`, `q`, `rp`, `rt`, `ruby`, `s`, `samp`, `section`, `small`, `span`, `strike`, `strong`, `sub`, `sup`, `table`, `tbody`, `td`, `template`, `tfoot`, `th`, `thead`, `time`, `tr`, `tt`, `u`, `ul`, `var`

## Roadmap
[View the development roadmap in the wiki](https://github.com/Sub6Resources/flutter_html/wiki/Roadmap)

### Partially supported elements:
> These are common elements that aren't yet fully supported, but won't be ignored and will still render somewhat correctly.

`center`, `font`
## Currently Supported CSS Attributes:
> Coming soon!

### List of _planned_ supported elements:
> These are elements that are planned, but present a specific challenge that makes them somewhat difficult to implement.

`audio`, `details`, `source`, `summary`, `svg`, `track`, `video`, `wbr`

### List of elements that I don't plan on implementing:
### Elements with planned support:

> Feel free to open an issue if you have a good reason and feel like you can convince me to implement
them. A _well written_ and _complete_ pull request implementing one of these is always welcome,
though I cannot promise I will merge them.

> Note: These unsupported tags will just be ignored.

`applet`, `area`, `base`, `basefont`, `button`, `canvas`, `col`, `colgroup`, `datalist`, `dialog`, `dir`, `embed`, `fieldset`, `form`, `frame`, `frameset`, `head`, `iframe`, `input`, `label`, `legend`, `link`, `map`, `meta`, `meter`, `noframe`, `object`, `optgroup`, `option`, `output`, `param`, `picture`, `progress`, `script`, `select`, `style`, `textarea`, `title`

See the [development roadmap](https://github.com/Sub6Resources/flutter_html/wiki/Roadmap) for the list of elements and css attributes I plan on supporting.

## Why this package?

This package is designed with simplicity in mind. Flutter currently does not support rendering of web content
into the widget tree. This package is designed to be a reasonable alternative for rendering static web content
until official support is added.

### Update:
The official Flutter WebView package has been created and is in a developer preview. It's not stable yet, so I'll continue to support this project at least until webview_flutter hits 1.0.0.

Check out the official Flutter WebView package here: https://pub.dartlang.org/packages/webview_flutter

This package is designed with simplicity in mind. Originally created to allow basic rendering of HTML content into the Flutter widget tree,
this project has expanded to include support for basic styling as well!.

## Example Usage:

Html(
(For a much more extensive example, look at example/main.dart).
```dart
Widget html = Html(
data: """
<!--For a much more extensive example, look at example/main.dart-->
<div>
<h1>Demo Page</h1>
<p>This is a fantastic nonexistent product that you should buy!</p>
<h2>Pricing</h2>
<p>Lorem ipsum <b>dolor</b> sit amet.</p>
<h2>The Team</h2>
<p>There isn't <i>really</i> a team...</p>
<h2>Installation</h2>
<p>You <u>cannot</u> install a nonexistent product!</p>
<p>This is a fantastic product that you should buy!</p>
<h3>Features</h3>
<ul>
<li>It actually works</li>
<li>It exists</li>
<li>It doesn't cost much!</li>
</ul>
<!--You can pretty much put any html in here!-->
</div>
""",
//Optional parameters:
padding: EdgeInsets.all(8.0),
backgroundColor: Colors.white70,
defaultTextStyle: TextStyle(fontFamily: 'serif'),
linkStyle: const TextStyle(
color: Colors.redAccent,
),
onLinkTap: (url) {
// open url in a webview
},
style: {
"div": Style(
block: Block(
margin: EdgeInsets.all(16),
border: Border.all(width: 6),
backgroundColor: Colors.grey,
),
textStyle: TextStyle(
color: Colors.red,
),
),
},
onImageTap: (src) {
// Display the image in large form.
},
//Must have useRichText set to false for this to work.
customRender: (node, children) {
if(node is dom.Element) {
switch(node.localName) {
case "video": return Chewie(...);
case "custom_tag": return CustomWidget(...);
}
}
},
customTextAlign: (dom.Node node) {
if (node is dom.Element) {
switch (node.localName) {
case "p":
return TextAlign.justify;
}
}
},
customTextStyle: (dom.Node node, TextStyle baseStyle) {
if (node is dom.Element) {
switch (node.localName) {
case "p":
return baseStyle.merge(TextStyle(height: 2, fontSize: 20));
}
}
return baseStyle;
},
)

## `useRichText` parameter

This package has a known issue where text does not wrap correctly. Setting `useRichText` to true fixes the issue
by using an alternate parser. The alternate parser, however, does not support the `customRender` callback, and several elements
supported by the default parser are not supported by the alternate parser (see [#61](https://github.com/Sub6Resources/flutter_html/issues/61) for a list).
);
75 changes: 75 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.packages
.pub-cache/
.pub/
/build/

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

**/.flutter-plugins-dependencies
**/ios/Flutter/flutter_export_environment.sh
10 changes: 10 additions & 0 deletions example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 20e59316b8b8474554b38493b8ca888794b0234a
channel: stable

project_type: app
16 changes: 16 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# example

A new Flutter project.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
61 changes: 61 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}

flutter {
source '../..'
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
Loading