Skip to content

Commit

Permalink
Merge pull request #16 from alihassan143/optmize
Browse files Browse the repository at this point in the history
fix: html codec parser fixes
  • Loading branch information
alihassan143 authored Sep 30, 2023
2 parents 14d1f95 + 963cba2 commit cdee600
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 200 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 0.0.9+1

* optimiz parse logic
* documentation fixs
* using override dependency for pdf due to underline and italic issues
* update readme
## 0.0.9

* optimiz parse logic
* documentation fixs
* using override dependency for pdf due to underline and italic issues

## 0.0.8+2

* support for html table tag added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Add the following dependency to your `pubspec.yaml` file:

```yaml
dependencies:
htmltopdfwidgets: ^0.0.8+2
htmltopdfwidgets: ^0.0.9+1
```
## Usage
Expand Down
Binary file removed example.pdf
Binary file not shown.
75 changes: 49 additions & 26 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,55 @@ void main() {
createDocument();
}

const htmlText = ''' <h1>Heading Example</h1>
<p>This is a paragraph.</p>
<img src="image.jpg" alt="Example Image" />
<blockquote>This is a quote.</blockquote>
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
const htmlText = ''' <h1>AppFlowyEditor</h1>
<h2>👋 <strong>Welcome to</strong> <strong><em><a href="appflowy.io">AppFlowy Editor</a></em></strong></h2>
<p>AppFlowy Editor is a <strong>highly customizable</strong> <em>rich-text editor</em></p>
<hr />
<p><u>Here</u> is an example <del>your</del> you can give a try</p>
<span style="font-weight: bold;background-color: #cccccc;font-style: italic;">Span element</span>
<span style="font-weight: medium;text-decoration: underline;">Span element two</span>
<span style="font-weight: 900;text-decoration: line-through;">Span element three</span>
<a href="https://appflowy.io">This is an anchor tag!</a>
<img src="https://images.squarespace-cdn.com/content/v1/617f6f16b877c06711e87373/c3f23723-37f4-44d7-9c5d-6e2a53064ae7/Asset+10.png?format=1500w" />
<h3>Features!</h3>
<ul>
<li>[x] Customizable</li>
<li>[x] Test-covered</li>
<li>[ ] more to come!</li>
</ul>
<ol>
<li>First item</li>
<li>Second item</li>
</ol>
<li>List element</li>
<blockquote>
<p>This is a quote!</p>
</blockquote>
<code>
Code block
</code>
<em>Italic one</em> <i>Italic two</i>
<b>Bold tag</b>
<img src="http://appflowy.io" alt="AppFlowy">
<p>You can also use <strong><em>AppFlowy Editor</em></strong> as a component to build your own app.</p>
<h3>Awesome features</h3>
<p>If you have questions or feedback, please submit an issue on Github or join the community along with 1000+ builders!</p>
''';

createDocument() async {
Expand Down
46 changes: 23 additions & 23 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: archive
sha256: "0c8368c9b3f0abbc193b9d6133649a614204b528982bebc7026372d61677ce3a"
sha256: d4dc11707abb32ef756ab95678c0d6df54003d98277f7c9aeda14c48e7a38c2f
url: "https://pub.dev"
source: hosted
version: "3.3.7"
version: "3.4.3"
async:
dependency: transitive
description:
Expand All @@ -29,18 +29,18 @@ packages:
dependency: transitive
description:
name: bidi
sha256: dc00274c7edabae2ab30c676e736ea1eb0b1b7a1b436cb5fe372e431ccb39ab0
sha256: "1a7d0c696324b2089f72e7671fd1f1f64fef44c980f3cebc84e803967c597b63"
url: "https://pub.dev"
source: hosted
version: "2.0.6"
version: "2.0.10"
collection:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
convert:
dependency: transitive
description:
Expand All @@ -61,33 +61,33 @@ packages:
dependency: transitive
description:
name: csslib
sha256: "831883fb353c8bdc1d71979e5b342c7d88acfbc643113c14ae51e2442ea0f20f"
sha256: "706b5707578e0c1b4b7550f64078f0a0f19dec3f50a178ffae7006b0a9ca58fb"
url: "https://pub.dev"
source: hosted
version: "0.17.3"
version: "1.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.0.3"
html:
dependency: transitive
description:
name: html
sha256: "58e3491f7bf0b6a4ea5110c0c688877460d1a6366731155c4a4580e7ded773e8"
sha256: "3a7812d5bcd2894edf53dfaf8cd640876cf6cef50a8f238745c8b8120ea74d3a"
url: "https://pub.dev"
source: hosted
version: "0.15.3"
version: "0.15.4"
htmltopdfwidgets:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.0.8+1"
version: "0.0.8+2"
http:
dependency: transitive
description:
Expand All @@ -108,10 +108,10 @@ packages:
dependency: transitive
description:
name: image
sha256: a72242c9a0ffb65d03de1b7113bc4e189686fc07c7147b8b41811d0dd0e0d9bf
sha256: "028f61960d56f26414eb616b48b04eb37d700cbe477b7fb09bf1d7ce57fd9271"
url: "https://pub.dev"
source: hosted
version: "4.0.17"
version: "4.1.3"
js:
dependency: transitive
description:
Expand All @@ -132,10 +132,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -164,10 +164,10 @@ packages:
dependency: transitive
description:
name: petitparser
sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750
sha256: eeb2d1428ee7f4170e2bd498827296a18d4e7fc462b71727d111c0ac7707cfa6
url: "https://pub.dev"
source: hosted
version: "5.4.0"
version: "6.0.1"
pointycastle:
dependency: transitive
description:
Expand All @@ -188,10 +188,10 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -228,9 +228,9 @@ packages:
dependency: transitive
description:
name: xml
sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84"
sha256: af5e77e9b83f2f4adc5d3f0a4ece1c7f45a2467b695c2540381bac793e34e556
url: "https://pub.dev"
source: hosted
version: "6.3.0"
version: "6.4.2"
sdks:
dart: ">=3.0.3 <4.0.0"
1 change: 0 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dependencies:
htmltopdfwidgets:
path: ../


dev_dependencies:


Expand Down
100 changes: 51 additions & 49 deletions lib/src/attributes.dart
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
///
/// Supported partial rendering types:
/// bold, italic,
/// underline, strikethrough,
/// color, font,
/// href
///
/// Supported global rendering types:
/// heading: h1, h2, h3, h4, h5, h6, ...
/// block quote,
/// list: ordered list, bulleted list,
/// code block
///
/// This class defines various constants for supported rendering types
/// and attributes in a text processing system. It categorizes them into
/// partial rendering types and global rendering types.
class BuiltInAttributeKey {
static String bold = 'bold';
static String italic = 'italic';
static String underline = 'underline';
static String strikethrough = 'strikethrough';
static String color = 'color';
static String backgroundColor = 'backgroundColor';
static String font = 'font';
static String href = 'href';
// Partial rendering types
static String bold = 'bold'; // Text should be displayed in bold.
static String italic = 'italic'; // Text should be displayed in italic.
static String underline = 'underline'; // Text should be underlined.
static String strikethrough =
'strikethrough'; // Text should have a strikethrough line.
static String color = 'color'; // Text color customization.
static String backgroundColor =
'backgroundColor'; // Background color customization.
static String font = 'font'; // Font customization.
static String href = 'href'; // Hyperlink attribute for text.

static String subtype = 'subtype';
static String heading = 'heading';
static String h1 = 'h1';
static String h2 = 'h2';
static String h3 = 'h3';
static String h4 = 'h4';
static String h5 = 'h5';
static String h6 = 'h6';
// Global rendering types
static String subtype =
'subtype'; // Subtype for customizing rendering behavior.
static String heading =
'heading'; // Text should be treated as a heading (h1, h2, h3, etc.).
static String h1 = 'h1'; // Heading level 1.
static String h2 = 'h2'; // Heading level 2.
static String h3 = 'h3'; // Heading level 3.
static String h4 = 'h4'; // Heading level 4.
static String h5 = 'h5'; // Heading level 5.
static String h6 = 'h6'; // Heading level 6.

static String bulletedList = 'bulleted-list';
static String numberList = 'number-list';
static String bulletedList =
'bulleted-list'; // Text should be displayed in a bulleted list.
static String numberList =
'number-list'; // Text should be displayed in a numbered list.

static String quote = 'quote';
static String checkbox = 'checkbox';
static String code = 'code';
static String number = 'number';
static String quote = 'quote'; // Text should be displayed as a blockquote.
static String checkbox =
'checkbox'; // Text should be displayed as a checkbox.
static String code = 'code'; // Text should be displayed as code.
static String number =
'number'; // Text should be displayed as a numbered item.

// Lists of partial style keys and global style keys
static List<String> partialStyleKeys = [
BuiltInAttributeKey.bold,
BuiltInAttributeKey.italic,
BuiltInAttributeKey.underline,
BuiltInAttributeKey.strikethrough,
BuiltInAttributeKey.backgroundColor,
BuiltInAttributeKey.color,
BuiltInAttributeKey.href,
BuiltInAttributeKey.code,
bold,
italic,
underline,
strikethrough,
backgroundColor,
color,
href,
code,
];

static List<String> globalStyleKeys = [
BuiltInAttributeKey.subtype,
BuiltInAttributeKey.heading,
BuiltInAttributeKey.checkbox,
BuiltInAttributeKey.bulletedList,
BuiltInAttributeKey.numberList,
BuiltInAttributeKey.quote,
subtype,
heading,
checkbox,
bulletedList,
numberList,
quote,
];
}
Loading

0 comments on commit cdee600

Please sign in to comment.