saminsohag

fixed some issues and added tableBuilder and underlineText

## 1.1.2
* 🔗 Fixed text decoration color of link markdown component
* 📊 Fixed table column alignment support ([#65](https://github.com/Infinitix-LLC/gpt_markdown/issues/65))
* 🎨 Added `tableBuilder` parameter to customize table rendering
* 🔗 Fixed text decoration color of link markdown component
## 1.1.1
... ...
... ... @@ -32,7 +32,7 @@ gpt_markdown is a drop-in replacement for flutter_markdown, offering extended su
| 🔗 Links | ✅ |
| 📱 Selectable | ✅ |
| 🧩 Custom components | ✅ | |
| 📎 Underline | | 🔜 |
| 📎 Underline | ✅ | |
## ✨ Key Features
... ... @@ -86,6 +86,11 @@ Render a wide variety of content with full Markdown and LaTeX support, including
*Italic text*
```
- <u>Underline text</u>
```
<u>Underline text</u>
```
- heading texts
```
... ...
... ... @@ -123,5 +123,28 @@ darkTheme: ThemeData(
),
```
Use `tableBuilder` to customize table rendering:
```dart
GptMarkdown(
markdownText,
tableBuilder: (context, tableRows, textStyle, config) {
return Table(
border: TableBorder.all(
width: 1,
color: Colors.red,
),
children: tableRows.map((e) {
return TableRow(
children: e.fields.map((e) {
return Text(e.data);
}).toList(),
);
}).toList(),
);
},
);
```
Please see the [README.md](https://github.com/Infinitix-LLC/gpt_markdown) and also [example](https://github.com/Infinitix-LLC/gpt_markdown/tree/main/example/lib/main.dart) app for more details.
... ...
... ... @@ -329,6 +329,12 @@ This document was created to test the robustness of Markdown parsers and to ensu
@override
Widget build(BuildContext context) {
// var data = '''|asdfasfd|asdfasf|
// |---|---|
// |sohag|asdfasf|
// |asdfasf|asdfasf|
// ''';
return GptMarkdownTheme(
gptThemeData: GptMarkdownTheme.of(context).copyWith(
highlightColor: Colors.purple,
... ... @@ -411,6 +417,7 @@ This document was created to test the robustness of Markdown parsers and to ensu
ListenableBuilder(
listenable: _controller,
builder: (context, _) {
var data = _controller.text;
return Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
... ... @@ -440,7 +447,7 @@ This document was created to test the robustness of Markdown parsers and to ensu
child: Builder(
builder: (context) {
Widget child = GptMarkdown(
_controller.text,
data,
textDirection: _direction,
onLinkTap: (url, title) {
debugPrint(url);
... ... @@ -614,6 +621,24 @@ This document was created to test the robustness of Markdown parsers and to ensu
),
);
},
// tableBuilder: (context, tableRows,
// textStyle, config) {
// return Table(
// border: TableBorder.all(
// width: 1,
// color: Colors.red,
// ),
// children: tableRows.map((e) {
// return TableRow(
// children: e.fields.map((e) {
// return Text(e.data);
// }).toList(),
// );
// }).toList(),
// );
// },
// components: [
// CodeBlockMd(),
// NewLines(),
... ...
... ... @@ -49,6 +49,15 @@ typedef LinkBuilder =
TextStyle style,
);
/// A builder function for the table.
typedef TableBuilder =
Widget Function(
BuildContext context,
List<CustomTableRow> tableRows,
TextStyle textStyle,
GptMarkdownConfig config,
);
/// A builder function for the highlight.
typedef HighlightBuilder =
Widget Function(BuildContext context, String text, TextStyle style);
... ... @@ -83,6 +92,7 @@ class GptMarkdownConfig {
this.overflow,
this.components,
this.inlineComponents,
this.tableBuilder,
});
/// The direction of the text.
... ... @@ -142,6 +152,9 @@ class GptMarkdownConfig {
/// The list of inline components.
final List<MarkdownComponent>? inlineComponents;
/// The table builder.
final TableBuilder? tableBuilder;
/// A copy of the configuration with the specified parameters.
GptMarkdownConfig copyWith({
TextStyle? style,
... ... @@ -163,6 +176,7 @@ class GptMarkdownConfig {
final UnOrderedListBuilder? unOrderedListBuilder,
final List<MarkdownComponent>? components,
final List<MarkdownComponent>? inlineComponents,
final TableBuilder? tableBuilder,
}) {
return GptMarkdownConfig(
style: style ?? this.style,
... ... @@ -184,6 +198,7 @@ class GptMarkdownConfig {
unOrderedListBuilder: unOrderedListBuilder ?? this.unOrderedListBuilder,
components: components ?? this.components,
inlineComponents: inlineComponents ?? this.inlineComponents,
tableBuilder: tableBuilder ?? this.tableBuilder,
);
}
... ...
... ... @@ -40,6 +40,7 @@ class GptMarkdown extends StatelessWidget {
this.overflow,
this.orderedListBuilder,
this.unOrderedListBuilder,
this.tableBuilder,
this.components,
this.inlineComponents,
this.useDollarSignsForLatex = false,
... ... @@ -100,6 +101,9 @@ class GptMarkdown extends StatelessWidget {
/// Whether to use dollar signs for LaTeX.
final bool useDollarSignsForLatex;
/// The table builder.
final TableBuilder? tableBuilder;
/// The list of components.
/// ```dart
/// List<MarkdownComponent> components = [
... ... @@ -202,6 +206,7 @@ class GptMarkdown extends StatelessWidget {
unOrderedListBuilder: unOrderedListBuilder,
components: components,
inlineComponents: inlineComponents,
tableBuilder: tableBuilder,
),
),
);
... ...
... ... @@ -1058,6 +1058,36 @@ class TableMd extends BlockMd {
columnAlignments.add(TextAlign.left);
}
var tableBuilder = config.tableBuilder;
if (tableBuilder != null) {
var customTable =
List<CustomTableRow?>.generate(value.length, (index) {
var isHeader = index == 0;
var row = value[index];
if (row.isEmpty) {
return null;
}
if (index == 1) {
return null;
}
var fields = List<CustomTableField>.generate(maxCol, (index) {
var field = row[index];
return CustomTableField(
data: field ?? "",
alignment: columnAlignments[index],
);
});
return CustomTableRow(isHeader: isHeader, fields: fields);
}).nonNulls.toList();
return tableBuilder(
context,
customTable,
config.style ?? const TextStyle(),
config,
);
}
final controller = ScrollController();
return Scrollbar(
controller: controller,
... ... @@ -1195,3 +1225,17 @@ class UnderLineMd extends InlineMd {
);
}
}
class CustomTableField {
final String data;
final TextAlign alignment;
CustomTableField({required this.data, this.alignment = TextAlign.left});
}
class CustomTableRow {
final bool isHeader;
final List<CustomTableField> fields;
CustomTableRow({this.isHeader = false, required this.fields});
}
... ...
name: gpt_markdown
description: "Powerful Flutter Markdown & LaTeX Renderer: Rich Text, Math, Tables, Links, and Text Selection. Ideal for ChatGPT, Gemini, and more."
version: 1.1.1
version: 1.1.2
homepage: https://github.com/Infinitix-LLC/gpt_markdown
environment:
... ...