saminsohag

Table heading color added

@@ -122,84 +122,94 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex @@ -122,84 +122,94 @@ 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(  
127 - children: [  
128 - AnimatedBuilder(  
129 - animation: _controller,  
130 - builder: (context, _) {  
131 - return Material(  
132 - // color: Theme.of(context).colorScheme.surfaceVariant,  
133 - shape: RoundedRectangleBorder(  
134 - side: BorderSide(  
135 - width: 1,  
136 - color: Theme.of(context).colorScheme.outline),  
137 - ),  
138 - child:  
139 - LayoutBuilder(builder: (context, constraints) {  
140 - return Theme(  
141 - data: Theme.of(context).copyWith(  
142 - textTheme: const TextTheme(  
143 - // For H1.  
144 - headlineLarge: TextStyle(fontSize: 55),  
145 - // For H2.  
146 - headlineMedium: TextStyle(fontSize: 45),  
147 - // For H3.  
148 - headlineSmall: TextStyle(fontSize: 35),  
149 - // For H4.  
150 - titleLarge: TextStyle(fontSize: 25),  
151 - // For H5.  
152 - titleMedium: TextStyle(fontSize: 15),  
153 - // For H6.  
154 - titleSmall: TextStyle(fontSize: 10),  
155 - ), 125 + child: ListView(
  126 + children: [
  127 + AnimatedBuilder(
  128 + animation: _controller,
  129 + builder: (context, _) {
  130 + return Material(
  131 + // color: Theme.of(context).colorScheme.surfaceVariant,
  132 + shape: RoundedRectangleBorder(
  133 + side: BorderSide(
  134 + width: 1,
  135 + color: Theme.of(context).colorScheme.outline),
  136 + ),
  137 + child:
  138 + LayoutBuilder(builder: (context, constraints) {
  139 + return Theme(
  140 + data: Theme.of(context).copyWith(
  141 + textTheme: const TextTheme(
  142 + // For H1.
  143 + headlineLarge: TextStyle(fontSize: 55),
  144 + // For H2.
  145 + headlineMedium: TextStyle(fontSize: 45),
  146 + // For H3.
  147 + headlineSmall: TextStyle(fontSize: 35),
  148 + // For H4.
  149 + titleLarge: TextStyle(fontSize: 25),
  150 + // For H5.
  151 + titleMedium: TextStyle(fontSize: 15),
  152 + // For H6.
  153 + titleSmall: TextStyle(fontSize: 10),
156 ), 154 ),
157 - child: TexMarkdown(  
158 - _controller.text,  
159 - textDirection: _direction,  
160 - onLinkTab: (url, title) {  
161 - log(title, name: "title");  
162 - log(url, name: "url");  
163 - },  
164 - textAlign: TextAlign.justify,  
165 - // textScaler: const TextScaler.linear(1.3),  
166 - textScaler: MediaQuery.textScalerOf(context),  
167 - style: const TextStyle(  
168 - // Regular text font size here.  
169 - fontSize: 15,  
170 - ),  
171 - latexWorkaround: (tex) =>  
172 - tex.replaceAllMapped(RegExp(r"align\*"),  
173 - (match) => "aligned"),  
174 - latexBuilder: (contex, tex) {  
175 - var controller = ScrollController();  
176 - return Column(  
177 - children: [  
178 - Scrollbar( 155 + ),
  156 + child: TexMarkdown(
  157 + _controller.text,
  158 + textDirection: _direction,
  159 + onLinkTab: (url, title) {
  160 + log(title, name: "title");
  161 + log(url, name: "url");
  162 + },
  163 + textAlign: TextAlign.justify,
  164 + // textScaler: const TextScaler.linear(1.3),
  165 + textScaler: MediaQuery.textScalerOf(context),
  166 + style: const TextStyle(
  167 + // Regular text font size here.
  168 + fontSize: 15,
  169 + ),
  170 + latexWorkaround: (tex) =>
  171 + tex.replaceAllMapped(RegExp(r"align\*"),
  172 + (match) => "aligned"),
  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 + }
  186 + var controller = ScrollController();
  187 + return Column(
  188 + children: [
  189 + Scrollbar(
  190 + controller: controller,
  191 + child: SingleChildScrollView(
179 controller: controller, 192 controller: controller,
180 - child: SingleChildScrollView(  
181 - controller: controller,  
182 - scrollDirection: Axis.horizontal,  
183 - child: Math.tex(  
184 - tex,  
185 - textStyle: const TextStyle(  
186 - fontSize: 17,  
187 - ), 193 + scrollDirection: Axis.horizontal,
  194 + child: Math.tex(
  195 + tex,
  196 + textStyle: const TextStyle(
  197 + fontSize: 17,
188 ), 198 ),
189 ), 199 ),
190 ), 200 ),
191 - ],  
192 - );  
193 - },  
194 - ),  
195 - // child: const Text("Hello"),  
196 - );  
197 - }),  
198 - );  
199 - },  
200 - ),  
201 - ],  
202 - ), 201 + ),
  202 + ],
  203 + );
  204 + },
  205 + ),
  206 + // child: const Text("Hello"),
  207 + );
  208 + }),
  209 + );
  210 + },
  211 + ),
  212 + ],
203 ), 213 ),
204 ), 214 ),
205 ConstrainedBox( 215 ConstrainedBox(
@@ -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();