saminsohag

Table heading color added

@@ -122,8 +122,7 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex @@ -122,8 +122,7 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
122 Column( 122 Column(
123 children: [ 123 children: [
124 Expanded( 124 Expanded(
125 - child: SingleChildScrollView(  
126 - child: Column( 125 + child: ListView(
127 children: [ 126 children: [
128 AnimatedBuilder( 127 AnimatedBuilder(
129 animation: _controller, 128 animation: _controller,
@@ -172,6 +171,18 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex @@ -172,6 +171,18 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
172 tex.replaceAllMapped(RegExp(r"align\*"), 171 tex.replaceAllMapped(RegExp(r"align\*"),
173 (match) => "aligned"), 172 (match) => "aligned"),
174 latexBuilder: (contex, tex) { 173 latexBuilder: (contex, tex) {
  174 + if (tex.contains(r"\begin{tabular}")) {
  175 + // return table.
  176 + String tableString = "|${(RegExp(
  177 + r"^\\begin\{tabular\}\{.*?\}(.*?)\\end\{tabular\}$",
  178 + multiLine: true,
  179 + dotAll: true,
  180 + ).firstMatch(tex)?[1] ?? "").trim()}|";
  181 + tableString = tableString
  182 + .replaceAll(r"\\", "|\n|")
  183 + .replaceAll("&", "|");
  184 + return TexMarkdown(tableString);
  185 + }
175 var controller = ScrollController(); 186 var controller = ScrollController();
176 return Column( 187 return Column(
177 children: [ 188 children: [
@@ -201,7 +212,6 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex @@ -201,7 +212,6 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
201 ], 212 ],
202 ), 213 ),
203 ), 214 ),
204 - ),  
205 ConstrainedBox( 215 ConstrainedBox(
206 constraints: const BoxConstraints(maxHeight: 200), 216 constraints: const BoxConstraints(maxHeight: 200),
207 child: Padding( 217 child: Padding(
@@ -58,6 +58,8 @@ class MdWidget extends StatelessWidget { @@ -58,6 +58,8 @@ class MdWidget extends StatelessWidget {
58 .asMap(), 58 .asMap(),
59 ) 59 )
60 .toList(); 60 .toList();
  61 + bool heading =
  62 + RegExp(r"^\|.*?\|\n\|-[-\\ |]*?-\|\n").hasMatch(eachLn.trim());
61 int maxCol = 0; 63 int maxCol = 0;
62 for (final each in value) { 64 for (final each in value) {
63 if (maxCol < each.keys.length) { 65 if (maxCol < each.keys.length) {
@@ -80,11 +82,23 @@ class MdWidget extends StatelessWidget { @@ -80,11 +82,23 @@ class MdWidget extends StatelessWidget {
80 color: Theme.of(context).colorScheme.onSurface, 82 color: Theme.of(context).colorScheme.onSurface,
81 ), 83 ),
82 children: value 84 children: value
  85 + .asMap()
  86 + .entries
83 .map<TableRow>( 87 .map<TableRow>(
84 - (e) => TableRow( 88 + (entry) => TableRow(
  89 + decoration: (heading)
  90 + ? BoxDecoration(
  91 + color: (entry.key == 0)
  92 + ? Theme.of(context)
  93 + .colorScheme
  94 + .surfaceVariant
  95 + : null,
  96 + )
  97 + : null,
85 children: List.generate( 98 children: List.generate(
86 maxCol, 99 maxCol,
87 (index) { 100 (index) {
  101 + var e = entry.value;
88 String data = e[index] ?? ""; 102 String data = e[index] ?? "";
89 if (RegExp(r"^---+$").hasMatch(data.trim())) { 103 if (RegExp(r"^---+$").hasMatch(data.trim())) {
90 return const SizedBox(); 104 return const SizedBox();