saminsohag

textDirection is added

... ... @@ -125,6 +125,7 @@ $hello$
scrollDirection: Axis.horizontal,
child: TexMarkdown(
_controller.text,
textDirection: TextDirection.rtl,
onLinkTab: (url, title) {
log(title, name: "title");
log(url, name: "url");
... ...
... ... @@ -479,10 +479,9 @@ packages:
tex_text:
dependency: transitive
description:
name: tex_text
sha256: d970cdcf16fb38b28f16b6118853434703191c9757117bc264c43c212d554949
url: "https://pub.dev"
source: hosted
path: "../../tex_text"
relative: true
source: path
version: "0.1.8"
tuple:
dependency: transitive
... ...
... ... @@ -47,6 +47,7 @@ abstract class MarkdownComponent {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
List<InlineSpan> spans = [];
... ... @@ -59,6 +60,7 @@ abstract class MarkdownComponent {
context,
element.trim(),
style,
textDirection,
onLinkTab,
));
spans.add(
... ... @@ -78,7 +80,13 @@ abstract class MarkdownComponent {
color: style?.color,
),
),
each.span(context, element.trim(), style, onLinkTab),
each.span(
context,
element.trim(),
style,
textDirection,
onLinkTab,
),
TextSpan(
text: "\n ",
style: TextStyle(
... ... @@ -102,6 +110,7 @@ abstract class MarkdownComponent {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
);
... ... @@ -119,6 +128,7 @@ abstract class InlineMd extends MarkdownComponent {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
);
String toHtml(String text);
... ... @@ -133,10 +143,11 @@ abstract class BlockMd extends MarkdownComponent {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
return WidgetSpan(
child: build(context, text, style, onLinkTab),
child: build(context, text, style, textDirection, onLinkTab),
alignment: PlaceholderAlignment.middle,
);
}
... ... @@ -145,6 +156,7 @@ abstract class BlockMd extends MarkdownComponent {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
);
String toHtml(String text);
... ... @@ -159,13 +171,17 @@ class HTag extends BlockMd {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
var match = exp.firstMatch(text.trim());
return Text.rich(TextSpan(
children: [
WidgetSpan(
child: TexText("${match?[2]}",
return Text.rich(
TextSpan(
children: [
WidgetSpan(
child: TexText(
"${match?[2]}",
textDirection: textDirection,
style: [
Theme.of(context)
.textTheme
... ... @@ -191,22 +207,26 @@ class HTag extends BlockMd {
.textTheme
.titleSmall
?.copyWith(color: style?.color),
][match![1]!.length - 1]),
),
if (match[1]!.length == 1) ...[
const TextSpan(
text: "\n ",
style: TextStyle(fontSize: 0, height: 0),
),
WidgetSpan(
child: CustomDivider(
height: 2,
color: style?.color ?? Theme.of(context).colorScheme.outline,
][match![1]!.length - 1],
// textDirection: textDirection,
),
),
if (match[1]!.length == 1) ...[
const TextSpan(
text: "\n ",
style: TextStyle(fontSize: 0, height: 0),
),
WidgetSpan(
child: CustomDivider(
height: 2,
color: style?.color ?? Theme.of(context).colorScheme.outline,
),
),
],
],
],
));
),
textDirection: textDirection,
);
}
@override
... ... @@ -225,6 +245,7 @@ class HrLine extends BlockMd {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
return CustomDivider(
... ... @@ -248,6 +269,7 @@ class CheckBoxMd extends BlockMd {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
var match = exp.firstMatch(text.trim());
... ... @@ -256,6 +278,7 @@ class CheckBoxMd extends BlockMd {
child: MdWidget(
"${match?[2]}",
onLinkTab: onLinkTab,
textDirection: textDirection,
style: style,
),
);
... ... @@ -280,6 +303,7 @@ class RadioButtonMd extends BlockMd {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
var match = exp.firstMatch(text.trim());
... ... @@ -288,6 +312,7 @@ class RadioButtonMd extends BlockMd {
child: MdWidget(
"${match?[2]}",
onLinkTab: onLinkTab,
textDirection: textDirection,
style: style,
),
);
... ... @@ -312,6 +337,7 @@ class UnOrderedList extends BlockMd {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
var match = exp.firstMatch(text.trim());
... ... @@ -320,6 +346,7 @@ class UnOrderedList extends BlockMd {
child: MdWidget(
"${match?[2]}",
onLinkTab: onLinkTab,
textDirection: textDirection,
style: style,
),
);
... ... @@ -347,6 +374,7 @@ class OrderedList extends BlockMd {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
var match = exp.firstMatch(text.trim());
... ... @@ -356,6 +384,7 @@ class OrderedList extends BlockMd {
child: MdWidget(
"${match?[2]}",
onLinkTab: onLinkTab,
textDirection: textDirection,
style: style,
),
);
... ... @@ -378,6 +407,7 @@ class BoldMd extends InlineMd {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
var match = exp.firstMatch(text.trim());
... ... @@ -387,6 +417,7 @@ class BoldMd extends InlineMd {
baseline: TextBaseline.alphabetic,
child: TexText(
"${match?[1]}",
textDirection: textDirection,
style: style?.copyWith(fontWeight: FontWeight.bold) ??
const TextStyle(fontWeight: FontWeight.bold),
),
... ... @@ -412,6 +443,7 @@ class ItalicMd extends InlineMd {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
var match = exp.firstMatch(text.trim());
... ... @@ -420,6 +452,7 @@ class ItalicMd extends InlineMd {
baseline: TextBaseline.alphabetic,
child: TexText(
"${match?[1]}",
textDirection: textDirection,
style:
(style ?? const TextStyle()).copyWith(fontStyle: FontStyle.italic),
),
... ... @@ -444,6 +477,7 @@ class ATagMd extends InlineMd {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
var match = exp.firstMatch(text.trim());
... ... @@ -462,6 +496,7 @@ class ATagMd extends InlineMd {
},
child: TexText(
"${match?[1]}",
textDirection: textDirection,
style: (style ?? const TextStyle()).copyWith(
color: Colors.blueAccent,
decorationColor: Colors.blue,
... ... @@ -489,6 +524,7 @@ class ImageMd extends InlineMd {
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
final void Function(String url, String title)? onLinkTab,
) {
var match = exp.firstMatch(text.trim());
... ... @@ -548,8 +584,13 @@ class ImageMd extends InlineMd {
/// Table component
class TableMd extends BlockMd {
@override
Widget build(BuildContext context, String text, TextStyle? style,
void Function(String url, String title)? onLinkTab) {
Widget build(
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
void Function(String url, String title)? onLinkTab,
) {
final List<Map<int, String>> value = text
.split('\n')
.map<Map<int, String>>(
... ... @@ -571,6 +612,7 @@ class TableMd extends BlockMd {
}
return Table(
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
textDirection: textDirection,
border: TableBorder.all(
width: 1,
color: Theme.of(context).colorScheme.onSurface,
... ... @@ -583,6 +625,7 @@ class TableMd extends BlockMd {
(index) => Center(
child: MdWidget(
(e[index] ?? "").trim(),
textDirection: textDirection,
onLinkTab: onLinkTab,
style: style,
),
... ... @@ -634,13 +677,19 @@ class TextMd extends InlineMd {
final RegExp exp = RegExp(".*");
@override
InlineSpan span(BuildContext context, String text, TextStyle? style,
void Function(String url, String title)? onLinkTab) {
InlineSpan span(
BuildContext context,
String text,
TextStyle? style,
TextDirection textDirection,
void Function(String url, String title)? onLinkTab,
) {
return WidgetSpan(
alignment: PlaceholderAlignment.baseline,
baseline: TextBaseline.alphabetic,
child: TexText(
text,
textDirection: textDirection,
style: style,
));
}
... ...
... ... @@ -6,8 +6,13 @@ import 'package:tex_markdown/markdown_component.dart';
/// It creates a markdown widget closed to each other.
class MdWidget extends StatelessWidget {
const MdWidget(this.exp,
{super.key, this.style, this.onLinkTab, this.followLinkColor = false});
{super.key,
this.style,
this.textDirection = TextDirection.ltr,
this.onLinkTab,
this.followLinkColor = false});
final String exp;
final TextDirection textDirection;
final TextStyle? style;
final void Function(String url, String title)? onLinkTab;
final bool followLinkColor;
... ... @@ -93,6 +98,7 @@ $value
),
WidgetSpan(
child: Table(
textDirection: textDirection,
defaultColumnWidth: CustomTableColumnWidth(),
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
border: TableBorder.all(
... ... @@ -107,6 +113,7 @@ $value
(index) => Center(
child: MdWidget(
(e[index] ?? "").trim(),
textDirection: textDirection,
onLinkTab: onLinkTab,
style: style,
),
... ... @@ -126,7 +133,12 @@ $value
} else {
list.addAll(
MarkdownComponent.generate(
context, eachLn.trim(), style, onLinkTab),
context,
eachLn.trim(),
style,
textDirection,
onLinkTab,
),
);
}
return "";
... ... @@ -137,6 +149,7 @@ $value
children: list,
style: style,
),
textDirection: textDirection,
);
}
}
... ...
... ... @@ -11,8 +11,10 @@ class TexMarkdown extends StatelessWidget {
super.key,
this.style,
this.followLinkColor = false,
this.textDirection = TextDirection.ltr,
this.onLinkTab,
});
final TextDirection textDirection;
final String data;
final TextStyle? style;
final void Function(String url, String title)? onLinkTab;
... ... @@ -30,6 +32,7 @@ class TexMarkdown extends StatelessWidget {
return ClipRRect(
child: MdWidget(
data.trim(),
textDirection: textDirection,
style: style,
onLinkTab: onLinkTab,
followLinkColor: followLinkColor,
... ...
... ... @@ -2,6 +2,7 @@ name: tex_markdown
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.
version: 0.1.9
homepage: https://github.com/saminsohag/flutter_packages/tree/main/tex_markdown
publish_to: "none"
environment:
sdk: '>=3.1.0 <4.0.0'
... ... @@ -10,7 +11,9 @@ environment:
dependencies:
flutter:
sdk: flutter
tex_text: ^0.1.8
# tex_text: ^0.1.8
tex_text:
path: ../tex_text
dev_dependencies:
flutter_test:
... ...
... ... @@ -14,12 +14,17 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State<MyApp> {
final TextEditingController _text = TextEditingController();
final TextEditingController _text = TextEditingController(
text: r"Some random text and $x^2+y^2=$ some thing");
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text("Tex Text.")),
appBar: AppBar(
title: const Text(
"Tex Text .",
textDirection: TextDirection.rtl,
)),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
... ... @@ -39,6 +44,7 @@ class _MyAppState extends State<MyApp> {
child: TexText(
// TexText.newEasySyntax(_text.text),
_text.text,
textDirection: TextDirection.rtl,
style: Theme.of(context)
.textTheme
.titleLarge
... ...
... ... @@ -182,7 +182,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
... ...
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
... ...
... ... @@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: args
sha256: c372bb384f273f0c2a8aaaa226dad84dc27c8519a691b888725dec59518ad53a
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
url: "https://pub.dev"
source: hosted
version: "2.4.1"
version: "2.4.2"
async:
dependency: transitive
description:
... ... @@ -45,18 +45,18 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
url: "https://pub.dev"
source: hosted
version: "1.0.5"
version: "1.0.6"
fake_async:
dependency: transitive
description:
... ... @@ -74,71 +74,63 @@ packages:
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"
flutter_math_fork:
dependency: transitive
description:
name: flutter_math_fork
sha256: a143a3a89131b578043ecbdb5e759c1033a1b3e9174f5cd1b979d93f4a7fb41c
sha256: "94bee4642892a94939af0748c6a7de0ff8318feee588379dcdfea7dc5cba06c8"
url: "https://pub.dev"
source: hosted
version: "0.7.1"
version: "0.7.2"
flutter_svg:
dependency: transitive
description:
name: flutter_svg
sha256: f991fdb1533c3caeee0cdc14b04f50f0c3916f0dbcbc05237ccbe4e3c6b93f3f
sha256: d39e7f95621fc84376bc0f7d504f05c3a41488c562f4a8ad410569127507402c
url: "https://pub.dev"
source: hosted
version: "2.0.5"
version: "2.0.9"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
lints:
dependency: transitive
description:
name: lints
sha256: "6b0206b0bf4f04961fc5438198ccb3a885685cd67d4d4a32cc20ad7f8adbe015"
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.1"
matcher:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
nested:
dependency: transitive
description:
... ... @@ -167,18 +159,18 @@ packages:
dependency: transitive
description:
name: petitparser
sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
url: "https://pub.dev"
source: hosted
version: "5.4.0"
version: "6.0.2"
provider:
dependency: transitive
description:
name: provider
sha256: cdbe7530b12ecd9eb455bdaa2fcb8d4dad22e80b8afb4798b41479d5ce26847f
sha256: "9a96a0a19b594dbc5bf0f1f27d2bc67d5f95957359b461cd9feb44ed6ae75096"
url: "https://pub.dev"
source: hosted
version: "6.0.5"
version: "6.1.1"
sky_engine:
dependency: transitive
description: flutter
... ... @@ -188,26 +180,26 @@ 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"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
... ... @@ -228,10 +220,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.1"
tex_text:
dependency: "direct dev"
description:
... ... @@ -243,34 +235,34 @@ packages:
dependency: transitive
description:
name: tuple
sha256: "0ea99cd2f9352b2586583ab2ce6489d1f95a5f6de6fb9492faaf97ae2060f0aa"
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.0.2"
vector_graphics:
dependency: transitive
description:
name: vector_graphics
sha256: "59a230f8bf37dd8b077335d1d64d895bccef0fb14f50730e3d79e8990bf3ed2b"
sha256: "18f6690295af52d081f6808f2f7c69f0eed6d7e23a71539d75f4aeb8f0062172"
url: "https://pub.dev"
source: hosted
version: "1.1.5+1"
version: "1.1.9+2"
vector_graphics_codec:
dependency: transitive
description:
name: vector_graphics_codec
sha256: "40781fe91c6d10a617c0289f7ec16cdb2d85a7f3654af2778c6d0adbf3bf45a3"
sha256: "531d20465c10dfac7f5cd90b60bbe4dd9921f1ec4ca54c83ebb176dbacb7bb2d"
url: "https://pub.dev"
source: hosted
version: "1.1.5+1"
version: "1.1.9+2"
vector_graphics_compiler:
dependency: transitive
description:
name: vector_graphics_compiler
sha256: "6ca1298b70edcc3486fdb14032f1a186a593f1b5f6b5e82fb10febddcb1c61bb"
sha256: "03012b0a33775c5530576b70240308080e1d5050f0faf000118c20e6463bc0ad"
url: "https://pub.dev"
source: hosted
version: "1.1.5+1"
version: "1.1.9+2"
vector_math:
dependency: transitive
description:
... ... @@ -279,14 +271,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
xml:
dependency: transitive
description:
name: xml
sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84"
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
url: "https://pub.dev"
source: hosted
version: "6.3.0"
version: "6.5.0"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.2.0 <4.0.0"
flutter: ">=3.7.0-0"
... ...
... ... @@ -18,10 +18,12 @@ class TexText extends StatelessWidget {
this.text, {
super.key,
TextStyle? style,
this.textDirection = TextDirection.ltr,
this.mathStyle = MathStyle.text,
}) : _style = style;
final String text;
final TextStyle? _style;
final TextDirection textDirection;
final MathStyle mathStyle;
// final TexAlignment alignment;
... ... @@ -130,6 +132,7 @@ class TexText extends StatelessWidget {
onErrorFallback: (err) {
return Text(
"\$${p0[1]}\$",
textDirection: textDirection,
style: style?.copyWith(
color: Theme.of(context).colorScheme.error) ??
TextStyle(color: Theme.of(context).colorScheme.error),
... ... @@ -154,6 +157,7 @@ class TexText extends StatelessWidget {
TextSpan(
children: spans,
),
textDirection: textDirection,
);
}
... ...