Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
gpt_markdown
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
saminsohag
2024-02-16 10:13:57 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
397e76430714c78d782fc9319bb0138bf459648b
397e7643
1 parent
39102613
Table heading color added
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
74 deletions
gpt_markdown/example/lib/main.dart
gpt_markdown/lib/md_widget.dart
gpt_markdown/example/lib/main.dart
View file @
397e764
...
...
@@ -122,84 +122,94 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
AnimatedBuilder(
animation: _controller,
builder: (context, _) {
return Material(
// color: Theme.of(context).colorScheme.surfaceVariant,
shape: RoundedRectangleBorder(
side: BorderSide(
width: 1,
color: Theme.of(context).colorScheme.outline),
),
child:
LayoutBuilder(builder: (context, constraints) {
return Theme(
data: Theme.of(context).copyWith(
textTheme: const TextTheme(
// For H1.
headlineLarge: TextStyle(fontSize: 55),
// For H2.
headlineMedium: TextStyle(fontSize: 45),
// For H3.
headlineSmall: TextStyle(fontSize: 35),
// For H4.
titleLarge: TextStyle(fontSize: 25),
// For H5.
titleMedium: TextStyle(fontSize: 15),
// For H6.
titleSmall: TextStyle(fontSize: 10),
),
child: ListView(
children: [
AnimatedBuilder(
animation: _controller,
builder: (context, _) {
return Material(
// color: Theme.of(context).colorScheme.surfaceVariant,
shape: RoundedRectangleBorder(
side: BorderSide(
width: 1,
color: Theme.of(context).colorScheme.outline),
),
child:
LayoutBuilder(builder: (context, constraints) {
return Theme(
data: Theme.of(context).copyWith(
textTheme: const TextTheme(
// For H1.
headlineLarge: TextStyle(fontSize: 55),
// For H2.
headlineMedium: TextStyle(fontSize: 45),
// For H3.
headlineSmall: TextStyle(fontSize: 35),
// For H4.
titleLarge: TextStyle(fontSize: 25),
// For H5.
titleMedium: TextStyle(fontSize: 15),
// For H6.
titleSmall: TextStyle(fontSize: 10),
),
child: TexMarkdown(
_controller.text,
textDirection: _direction,
onLinkTab: (url, title) {
log(title, name: "title");
log(url, name: "url");
},
textAlign: TextAlign.justify,
// textScaler: const TextScaler.linear(1.3),
textScaler: MediaQuery.textScalerOf(context),
style: const TextStyle(
// Regular text font size here.
fontSize: 15,
),
latexWorkaround: (tex) =>
tex.replaceAllMapped(RegExp(r"align
\
*"),
(match) => "aligned"),
latexBuilder: (contex, tex) {
var controller = ScrollController();
return Column(
children: [
Scrollbar(
),
child: TexMarkdown(
_controller.text,
textDirection: _direction,
onLinkTab: (url, title) {
log(title, name: "title");
log(url, name: "url");
},
textAlign: TextAlign.justify,
// textScaler: const TextScaler.linear(1.3),
textScaler: MediaQuery.textScalerOf(context),
style: const TextStyle(
// Regular text font size here.
fontSize: 15,
),
latexWorkaround: (tex) =>
tex.replaceAllMapped(RegExp(r"align
\
*"),
(match) => "aligned"),
latexBuilder: (contex, tex) {
if (tex.contains(r"
\
begin{tabular}")) {
// return table.
String tableString = "|
${(RegExp(
r"^\\begin\{tabular\}
\
{.*?
\
}(.*?)
\\
end
\
{tabular
\
}
$
",
multiLine: true,
dotAll: true,
).firstMatch(tex)?[1] ?? "").trim()}|";
tableString = tableString
.replaceAll(r"
\\
", "|
\n
|")
.replaceAll("&", "|");
return TexMarkdown(tableString);
}
var controller = ScrollController();
return Column(
children: [
Scrollbar(
controller: controller,
child: SingleChildScrollView(
controller: controller,
child: SingleChildScrollView(
controller: controller,
scrollDirection: Axis.horizontal,
child: Math.tex(
tex,
textStyle: const TextStyle(
fontSize: 17,
),
scrollDirection: Axis.horizontal,
child: Math.tex(
tex,
textStyle: const TextStyle(
fontSize: 17,
),
),
),
],
);
},
),
// child: const Text("Hello"),
);
}),
);
},
),
],
),
),
],
);
},
),
// child: const Text("Hello"),
);
}),
);
},
),
],
),
),
ConstrainedBox(
...
...
gpt_markdown/lib/md_widget.dart
View file @
397e764
...
...
@@ -58,6 +58,8 @@ class MdWidget extends StatelessWidget {
.
asMap
(),
)
.
toList
();
bool
heading
=
RegExp
(
r"^\|.*?\|\n\|-[-\\ |]*?-\|\n"
).
hasMatch
(
eachLn
.
trim
());
int
maxCol
=
0
;
for
(
final
each
in
value
)
{
if
(
maxCol
<
each
.
keys
.
length
)
{
...
...
@@ -80,11 +82,23 @@ class MdWidget extends StatelessWidget {
color:
Theme
.
of
(
context
).
colorScheme
.
onSurface
,
),
children:
value
.
asMap
()
.
entries
.
map
<
TableRow
>(
(
e
)
=>
TableRow
(
(
entry
)
=>
TableRow
(
decoration:
(
heading
)
?
BoxDecoration
(
color:
(
entry
.
key
==
0
)
?
Theme
.
of
(
context
)
.
colorScheme
.
surfaceVariant
:
null
,
)
:
null
,
children:
List
.
generate
(
maxCol
,
(
index
)
{
var
e
=
entry
.
value
;
String
data
=
e
[
index
]
??
""
;
if
(
RegExp
(
r"^---+$"
).
hasMatch
(
data
.
trim
()))
{
return
const
SizedBox
();
...
...
Please
register
or
login
to post a comment