Showing
5 changed files
with
59 additions
and
20 deletions
@@ -56,17 +56,24 @@ class MyHomePage extends StatefulWidget { | @@ -56,17 +56,24 @@ class MyHomePage extends StatefulWidget { | ||
56 | } | 56 | } |
57 | 57 | ||
58 | class _MyHomePageState extends State<MyHomePage> { | 58 | class _MyHomePageState extends State<MyHomePage> { |
59 | - final TextEditingController _controller = | ||
60 | - TextEditingController(text: '''# hi how are you? | ||
61 | -## hi how are you? | 59 | + final TextEditingController _controller = TextEditingController(text: r''' |
60 | +# hi how are you?$my is^2$ | ||
61 | +## hi how are you$(\frac ab)^2$? | ||
62 | ### hi how are you? | 62 | ### hi how are you? |
63 | #### hi how are you? | 63 | #### hi how are you? |
64 | -##### hi how are you? | ||
65 | -###### hi how are you? | ||
66 | - | 64 | +##### hi how are you?$my name is x^2$ |
65 | +###### hi how are you?$x^2$ | ||
66 | +hello | ||
67 | --- | 67 | --- |
68 | -**bold text** | ||
69 | -*Italic text* | 68 | +my name is |
69 | + | ||
70 | +**bold$x^2\cfrac a{\cfrac ab}$ text** | ||
71 | +*Italic text$x^2\cfrac a{b}$* | ||
72 | +**hello** | ||
73 | +$hello$ | ||
74 | + | ||
75 | +$sdf\frac a{\frac ab}$ | ||
76 | +$hello$ | ||
70 | [Link]() | 77 | [Link]() |
71 | - unordered list | 78 | - unordered list |
72 | 1. ordered list 1 | 79 | 1. ordered list 1 |
@@ -238,15 +238,15 @@ packages: | @@ -238,15 +238,15 @@ packages: | ||
238 | path: ".." | 238 | path: ".." |
239 | relative: true | 239 | relative: true |
240 | source: path | 240 | source: path |
241 | - version: "0.1.1" | 241 | + version: "0.1.2" |
242 | tex_text: | 242 | tex_text: |
243 | dependency: transitive | 243 | dependency: transitive |
244 | description: | 244 | description: |
245 | name: tex_text | 245 | name: tex_text |
246 | - sha256: "33bd11ec8eb58ca9d32919a71629ab80d704405da1a6e03d48ec3f6a266f1267" | 246 | + sha256: "46942a9587170f5130d2f7110083abd4335b66d763b0cf6a241c80e74826d71d" |
247 | url: "https://pub.dev" | 247 | url: "https://pub.dev" |
248 | source: hosted | 248 | source: hosted |
249 | - version: "0.1.4" | 249 | + version: "0.1.5" |
250 | tuple: | 250 | tuple: |
251 | dependency: transitive | 251 | dependency: transitive |
252 | description: | 252 | description: |
@@ -50,7 +50,10 @@ abstract class MarkdownComponent { | @@ -50,7 +50,10 @@ abstract class MarkdownComponent { | ||
50 | if (each is InlineMd) { | 50 | if (each is InlineMd) { |
51 | if (spans.isNotEmpty) { | 51 | if (spans.isNotEmpty) { |
52 | spans.add( | 52 | spans.add( |
53 | - TextSpan(text: " ", style: style), | 53 | + TextSpan( |
54 | + text: " ", | ||
55 | + style: style, | ||
56 | + ), | ||
54 | ); | 57 | ); |
55 | } | 58 | } |
56 | spans.add(each.inlineSpan( | 59 | spans.add(each.inlineSpan( |
@@ -83,7 +86,9 @@ abstract class MarkdownComponent { | @@ -83,7 +86,9 @@ abstract class MarkdownComponent { | ||
83 | if (spans.isNotEmpty) { | 86 | if (spans.isNotEmpty) { |
84 | children.add( | 87 | children.add( |
85 | Text.rich( | 88 | Text.rich( |
86 | - TextSpan(children: List.from(spans)), | 89 | + TextSpan( |
90 | + children: List.from(spans), | ||
91 | + ), | ||
87 | textAlign: TextAlign.left, | 92 | textAlign: TextAlign.left, |
88 | ), | 93 | ), |
89 | ); | 94 | ); |
@@ -168,7 +173,13 @@ class HTag extends BlockMd { | @@ -168,7 +173,13 @@ class HTag extends BlockMd { | ||
168 | ), | 173 | ), |
169 | ], | 174 | ], |
170 | ), | 175 | ), |
171 | - if (match[1]!.length == 1) const Divider(height: 6), | 176 | + if (match[1]!.length == 1) |
177 | + Divider( | ||
178 | + height: 6, | ||
179 | + thickness: 2, | ||
180 | + color: | ||
181 | + style?.color ?? Theme.of(context).colorScheme.onSurfaceVariant, | ||
182 | + ), | ||
172 | ], | 183 | ], |
173 | ); | 184 | ); |
174 | } | 185 | } |
@@ -190,8 +201,10 @@ class HrLine extends BlockMd { | @@ -190,8 +201,10 @@ class HrLine extends BlockMd { | ||
190 | TextStyle? style, | 201 | TextStyle? style, |
191 | final void Function(String url, String title)? onLinkTab, | 202 | final void Function(String url, String title)? onLinkTab, |
192 | ) { | 203 | ) { |
193 | - return const Divider( | ||
194 | - height: 5, | 204 | + return Divider( |
205 | + height: 6, | ||
206 | + thickness: 2, | ||
207 | + color: style?.color ?? Theme.of(context).colorScheme.onSurfaceVariant, | ||
195 | ); | 208 | ); |
196 | } | 209 | } |
197 | 210 | ||
@@ -393,6 +406,8 @@ class BoldMd extends InlineMd { | @@ -393,6 +406,8 @@ class BoldMd extends InlineMd { | ||
393 | var match = exp.firstMatch(text.trim()); | 406 | var match = exp.firstMatch(text.trim()); |
394 | return WidgetSpan( | 407 | return WidgetSpan( |
395 | // text: "${match?[1]}", | 408 | // text: "${match?[1]}", |
409 | + alignment: PlaceholderAlignment.baseline, | ||
410 | + baseline: TextBaseline.alphabetic, | ||
396 | child: TexText( | 411 | child: TexText( |
397 | "${match?[1]}", | 412 | "${match?[1]}", |
398 | style: style?.copyWith(fontWeight: FontWeight.bold) ?? | 413 | style: style?.copyWith(fontWeight: FontWeight.bold) ?? |
@@ -423,6 +438,8 @@ class ItalicMd extends InlineMd { | @@ -423,6 +438,8 @@ class ItalicMd extends InlineMd { | ||
423 | ) { | 438 | ) { |
424 | var match = exp.firstMatch(text.trim()); | 439 | var match = exp.firstMatch(text.trim()); |
425 | return WidgetSpan( | 440 | return WidgetSpan( |
441 | + alignment: PlaceholderAlignment.baseline, | ||
442 | + baseline: TextBaseline.alphabetic, | ||
426 | child: TexText( | 443 | child: TexText( |
427 | "${match?[1]}", | 444 | "${match?[1]}", |
428 | style: | 445 | style: |
@@ -455,6 +472,8 @@ class ATagMd extends InlineMd { | @@ -455,6 +472,8 @@ class ATagMd extends InlineMd { | ||
455 | return const TextSpan(); | 472 | return const TextSpan(); |
456 | } | 473 | } |
457 | return WidgetSpan( | 474 | return WidgetSpan( |
475 | + alignment: PlaceholderAlignment.baseline, | ||
476 | + baseline: TextBaseline.alphabetic, | ||
458 | child: GestureDetector( | 477 | child: GestureDetector( |
459 | onTap: () { | 478 | onTap: () { |
460 | if (onLinkTab == null) { | 479 | if (onLinkTab == null) { |
@@ -502,7 +521,7 @@ class ImageMd extends InlineMd { | @@ -502,7 +521,7 @@ class ImageMd extends InlineMd { | ||
502 | height = double.tryParse(size?[2]?.toString().trim() ?? 'a'); | 521 | height = double.tryParse(size?[2]?.toString().trim() ?? 'a'); |
503 | } | 522 | } |
504 | return WidgetSpan( | 523 | return WidgetSpan( |
505 | - // alignment: PlaceholderAlignment.middle, | 524 | + alignment: PlaceholderAlignment.bottom, |
506 | child: SizedBox( | 525 | child: SizedBox( |
507 | width: width, | 526 | width: width, |
508 | height: height, | 527 | height: height, |
@@ -526,7 +545,15 @@ class ImageMd extends InlineMd { | @@ -526,7 +545,15 @@ class ImageMd extends InlineMd { | ||
526 | @override | 545 | @override |
527 | String toHtml(String text) { | 546 | String toHtml(String text) { |
528 | var match = exp.firstMatch(text.trim()); | 547 | var match = exp.firstMatch(text.trim()); |
529 | - return '<img src="${match?[2].toString().trim()}">'; | 548 | + double? height; |
549 | + double? width; | ||
550 | + if (match?[1] != null) { | ||
551 | + var size = RegExp(r"^([0-9]+)?x?([0-9]+)?") | ||
552 | + .firstMatch(match![1].toString().trim()); | ||
553 | + width = double.tryParse(size?[1]?.toString().trim() ?? 'a'); | ||
554 | + height = double.tryParse(size?[2]?.toString().trim() ?? 'a'); | ||
555 | + } | ||
556 | + return '<img src="${match?[2].toString().trim()}" height="$height" width="$width">'; | ||
530 | } | 557 | } |
531 | } | 558 | } |
532 | 559 |
1 | name: tex_markdown | 1 | name: tex_markdown |
2 | description: This package is used to create flutter widget that can render markdown and latex formulas. It is very simple to use and uses native flutter components. | 2 | description: This package is used to create flutter widget that can render markdown and latex formulas. It is very simple to use and uses native flutter components. |
3 | -version: 0.1.1 | 3 | +version: 0.1.2 |
4 | homepage: https://github.com/saminsohag/flutter_packages/tree/main/tex_markdown | 4 | homepage: https://github.com/saminsohag/flutter_packages/tree/main/tex_markdown |
5 | 5 | ||
6 | environment: | 6 | environment: |
@@ -10,7 +10,7 @@ environment: | @@ -10,7 +10,7 @@ environment: | ||
10 | dependencies: | 10 | dependencies: |
11 | flutter: | 11 | flutter: |
12 | sdk: flutter | 12 | sdk: flutter |
13 | - tex_text: ^0.1.4 | 13 | + tex_text: ^0.1.5 |
14 | 14 | ||
15 | dev_dependencies: | 15 | dev_dependencies: |
16 | flutter_test: | 16 | flutter_test: |
-
Please register or login to post a comment