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 00:23:50 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9d27f09ba545969d4186074f014f15ab8f91ff64
9d27f09b
1 parent
04e68264
Scrolling feature of block type latex added
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
139 additions
and
95 deletions
gpt_markdown/example/lib/main.dart
gpt_markdown/example/pubspec.lock
gpt_markdown/example/pubspec.yaml
gpt_markdown/lib/gpt_markdown.dart
gpt_markdown/lib/markdown_component.dart
gpt_markdown/lib/md_widget.dart
gpt_markdown/example/lib/main.dart
View file @
9d27f09
import
'dart:developer'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_math_fork/flutter_math.dart'
;
import
'package:gpt_markdown/gpt_markdown.dart'
;
void
main
(
)
{
...
...
@@ -125,57 +126,65 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
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),
),
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"),
),
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,
),
// child: const Text("Hello"),
);
}),
);
}),
latexWorkaround: (tex) => tex.replaceAllMapped(
RegExp(r"align
\
*"), (match) => "aligned"),
latexBuilder: (contex, tex) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Math.tex(
tex,
textStyle: const TextStyle(fontSize: 17),
),
);
},
),
// child: const Text("Hello"),
);
}),
);
},
),
],
),
),
...
...
gpt_markdown/example/pubspec.lock
View file @
9d27f09
...
...
@@ -143,7 +143,7 @@ packages:
source: hosted
version: "2.0.3"
flutter_math_fork:
dependency:
transitive
dependency:
"direct main"
description:
name: flutter_math_fork
sha256: "94bee4642892a94939af0748c6a7de0ff8318feee588379dcdfea7dc5cba06c8"
...
...
gpt_markdown/example/pubspec.yaml
View file @
9d27f09
...
...
@@ -20,6 +20,7 @@ dependencies:
path_provider
:
^2.0.14
permission_handler
:
^10.2.0
file_picker
:
^5.2.10
flutter_math_fork
:
^0.7.2
dev_dependencies
:
flutter_test
:
...
...
gpt_markdown/lib/gpt_markdown.dart
View file @
9d27f09
...
...
@@ -16,6 +16,7 @@ class TexMarkdown extends StatelessWidget {
this
.
textAlign
,
this
.
textScaler
,
this
.
onLinkTab
,
this
.
latexBuilder
,
});
final
TextDirection
textDirection
;
final
String
data
;
...
...
@@ -24,6 +25,7 @@ class TexMarkdown extends StatelessWidget {
final
TextScaler
?
textScaler
;
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
;
final
String
Function
(
String
tex
)?
latexWorkaround
;
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
;
final
bool
followLinkColor
;
@override
...
...
@@ -38,6 +40,7 @@ class TexMarkdown extends StatelessWidget {
textScaler:
textScaler
,
followLinkColor:
followLinkColor
,
latexWorkaround:
latexWorkaround
,
latexBuilder:
latexBuilder
,
));
}
}
...
...
gpt_markdown/lib/markdown_component.dart
View file @
9d27f09
...
...
@@ -32,6 +32,7 @@ abstract class MarkdownComponent {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
List
<
InlineSpan
>
spans
=
[];
List
<
String
>
regexes
=
...
...
@@ -57,6 +58,7 @@ abstract class MarkdownComponent {
textDirection
,
onLinkTab
,
latexWorkaround
,
latexBuilder
,
));
}
else
{
if
(
each
is
BlockMd
)
{
...
...
@@ -76,6 +78,7 @@ abstract class MarkdownComponent {
textDirection
,
onLinkTab
,
latexWorkaround
,
latexBuilder
,
),
TextSpan
(
text:
"
\n
"
,
...
...
@@ -114,6 +117,7 @@ abstract class MarkdownComponent {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
);
RegExp
get
exp
;
...
...
@@ -133,6 +137,7 @@ abstract class InlineMd extends MarkdownComponent {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
);
}
...
...
@@ -148,6 +153,7 @@ abstract class BlockMd extends MarkdownComponent {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
return
WidgetSpan
(
child:
build
(
...
...
@@ -157,6 +163,7 @@ abstract class BlockMd extends MarkdownComponent {
textDirection
,
onLinkTab
,
latexWorkaround
,
latexBuilder
,
),
alignment:
PlaceholderAlignment
.
middle
,
);
...
...
@@ -169,6 +176,7 @@ abstract class BlockMd extends MarkdownComponent {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
);
}
...
...
@@ -184,6 +192,7 @@ class HTag extends BlockMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
Text
.
rich
(
...
...
@@ -221,6 +230,7 @@ class HTag extends BlockMd {
textDirection
,
(
url
,
title
)
{},
latexWorkaround
,
latexBuilder
,
)),
if
(
match
[
1
]!.
length
==
1
)
...[
const
TextSpan
(
...
...
@@ -259,6 +269,7 @@ class HrLine extends BlockMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
return
CustomDivider
(
height:
2
,
...
...
@@ -281,6 +292,7 @@ class CheckBoxMd extends BlockMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
CustomCb
(
...
...
@@ -292,6 +304,7 @@ class CheckBoxMd extends BlockMd {
textDirection:
textDirection
,
style:
style
,
latexWorkaround:
latexWorkaround
,
latexBuilder:
latexBuilder
,
),
);
}
...
...
@@ -311,6 +324,7 @@ class RadioButtonMd extends BlockMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
CustomRb
(
...
...
@@ -322,6 +336,7 @@ class RadioButtonMd extends BlockMd {
textDirection:
textDirection
,
style:
style
,
latexWorkaround:
latexWorkaround
,
latexBuilder:
latexBuilder
,
),
);
}
...
...
@@ -341,6 +356,7 @@ class IndentMd extends BlockMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
[
r"\\\[(.*?)\\\]"
,
...
...
@@ -356,14 +372,8 @@ class IndentMd extends BlockMd {
textDirection:
textDirection
,
child:
RichText
(
text:
TextSpan
(
children:
MarkdownComponent
.
generate
(
context
,
"
${match?[2]}
"
,
style
,
textDirection
,
onLinkTab
,
latexWorkaround
,
),
children:
MarkdownComponent
.
generate
(
context
,
"
${match?[2]}
"
,
style
,
textDirection
,
onLinkTab
,
latexWorkaround
,
latexBuilder
),
)),
);
}
...
...
@@ -383,6 +393,7 @@ class UnOrderedList extends BlockMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
);
return
UnorderedListView
(
...
...
@@ -396,6 +407,7 @@ class UnOrderedList extends BlockMd {
textDirection:
textDirection
,
style:
style
,
latexWorkaround:
latexWorkaround
,
latexBuilder:
latexBuilder
,
),
);
}
...
...
@@ -416,6 +428,7 @@ class OrderedList extends BlockMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
OrderedListView
(
...
...
@@ -428,6 +441,7 @@ class OrderedList extends BlockMd {
textDirection:
textDirection
,
style:
style
,
latexWorkaround:
latexWorkaround
,
latexBuilder:
latexBuilder
,
),
);
}
...
...
@@ -446,6 +460,7 @@ class BoldMd extends InlineMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
TextSpan
(
...
...
@@ -457,6 +472,7 @@ class BoldMd extends InlineMd {
textDirection
,
onLinkTab
,
latexWorkaround
,
latexBuilder
,
),
style:
style
?.
copyWith
(
fontWeight:
FontWeight
.
bold
)
??
const
TextStyle
(
fontWeight:
FontWeight
.
bold
),
...
...
@@ -479,51 +495,56 @@ class LatexMathMultyLine extends InlineMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
p0
=
exp
.
firstMatch
(
text
.
trim
());
p0
?.
group
(
0
);
String
mathText
=
p0
?[
1
]
??
p0
?[
2
]
??
""
;
var
workaround
=
latexWorkaround
??
(
String
tex
)
=>
tex
;
var
builder
=
latexBuilder
??
(
BuildContext
context
,
String
tex
)
=>
Math
.
tex
(
workaround
(
tex
),
textStyle:
style
?.
copyWith
(
fontFamily:
"SansSerif"
,
),
mathStyle:
MathStyle
.
display
,
textScaleFactor:
1
,
settings:
const
TexParserSettings
(
strict:
Strict
.
ignore
,
),
options:
MathOptions
(
sizeUnderTextStyle:
MathSize
.
large
,
color:
style
?.
color
??
Theme
.
of
(
context
).
colorScheme
.
onSurface
,
fontSize:
style
?.
fontSize
??
Theme
.
of
(
context
).
textTheme
.
bodyMedium
?.
fontSize
,
mathFontOptions:
FontOptions
(
fontFamily:
"Main"
,
fontWeight:
style
?.
fontWeight
??
FontWeight
.
normal
,
fontShape:
FontStyle
.
normal
,
),
textFontOptions:
FontOptions
(
fontFamily:
"Main"
,
fontWeight:
style
?.
fontWeight
??
FontWeight
.
normal
,
fontShape:
FontStyle
.
normal
,
),
style:
MathStyle
.
display
,
),
onErrorFallback:
(
err
)
{
return
Text
(
workaround
(
mathText
),
textDirection:
textDirection
,
style:
style
?.
copyWith
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
)
??
TextStyle
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
),
);
},
);
return
WidgetSpan
(
alignment:
PlaceholderAlignment
.
baseline
,
baseline:
TextBaseline
.
alphabetic
,
child:
Math
.
tex
(
workaround
(
mathText
),
textStyle:
style
?.
copyWith
(
fontFamily:
"SansSerif"
,
),
mathStyle:
MathStyle
.
display
,
textScaleFactor:
1
,
settings:
const
TexParserSettings
(
strict:
Strict
.
ignore
,
),
options:
MathOptions
(
sizeUnderTextStyle:
MathSize
.
large
,
color:
style
?.
color
??
Theme
.
of
(
context
).
colorScheme
.
onSurface
,
fontSize:
style
?.
fontSize
??
Theme
.
of
(
context
).
textTheme
.
bodyMedium
?.
fontSize
,
mathFontOptions:
FontOptions
(
fontFamily:
"Main"
,
fontWeight:
style
?.
fontWeight
??
FontWeight
.
normal
,
fontShape:
FontStyle
.
normal
,
),
textFontOptions:
FontOptions
(
fontFamily:
"Main"
,
fontWeight:
style
?.
fontWeight
??
FontWeight
.
normal
,
fontShape:
FontStyle
.
normal
,
),
style:
MathStyle
.
display
,
),
onErrorFallback:
(
err
)
{
return
Text
(
workaround
(
mathText
),
textDirection:
textDirection
,
style:
style
?.
copyWith
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
)
??
TextStyle
(
color:
Theme
.
of
(
context
).
colorScheme
.
error
),
);
},
),
child:
builder
(
context
,
mathText
),
);
}
}
...
...
@@ -547,6 +568,7 @@ class LatexMath extends InlineMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
p0
=
exp
.
firstMatch
(
text
.
trim
());
p0
?.
group
(
0
);
...
...
@@ -609,6 +631,7 @@ class ItalicMd extends InlineMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
return
TextSpan
(
...
...
@@ -619,6 +642,7 @@ class ItalicMd extends InlineMd {
textDirection
,
onLinkTab
,
latexWorkaround
,
latexBuilder
,
),
style:
(
style
??
const
TextStyle
()).
copyWith
(
fontStyle:
FontStyle
.
italic
),
);
...
...
@@ -638,6 +662,7 @@ class ATagMd extends InlineMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
if
(
match
?[
1
]
==
null
&&
match
?[
2
]
==
null
)
{
...
...
@@ -682,6 +707,7 @@ class ImageMd extends InlineMd {
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
match
=
exp
.
firstMatch
(
text
.
trim
());
double
?
height
;
...
...
@@ -733,6 +759,7 @@ class TableMd extends BlockMd {
TextDirection
textDirection
,
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
final
List
<
Map
<
int
,
String
>>
value
=
text
.
split
(
'
\n
'
)
...
...
gpt_markdown/lib/md_widget.dart
View file @
9d27f09
...
...
@@ -13,6 +13,7 @@ class MdWidget extends StatelessWidget {
this
.
textAlign
,
this
.
textScaler
,
this
.
latexWorkaround
,
this
.
latexBuilder
,
this
.
followLinkColor
=
false
});
final
String
exp
;
final
TextDirection
textDirection
;
...
...
@@ -21,6 +22,7 @@ class MdWidget extends StatelessWidget {
final
TextScaler
?
textScaler
;
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
;
final
String
Function
(
String
tex
)?
latexWorkaround
;
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
;
final
bool
followLinkColor
;
@override
...
...
@@ -94,6 +96,7 @@ class MdWidget extends StatelessWidget {
onLinkTab:
onLinkTab
,
style:
style
,
latexWorkaround:
latexWorkaround
,
latexBuilder:
latexBuilder
,
),
);
},
...
...
@@ -128,6 +131,7 @@ class MdWidget extends StatelessWidget {
textDirection
,
onLinkTab
,
latexWorkaround
,
latexBuilder
,
),
);
}
...
...
Please
register
or
login
to post a comment