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
2022-12-20 22:44:27 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
031d4f7e5b3234f88f07673b4c705694020e0b05
031d4f7e
1 parent
80c285fe
heading textstyle fixed and more supprot added
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
208 additions
and
50 deletions
tex_markdown/CHANGELOG.md
tex_markdown/README.md
tex_markdown/example/lib/main.dart
tex_markdown/example/pubspec.lock
tex_markdown/lib/md_widget.dart
tex_markdown/lib/tex_markdown.dart
tex_markdown/pubspec.yaml
tex_markdown/CHANGELOG.md
View file @
031d4f7
## 0.0.3
*
More support added and heading text style changed.
## 0.0.2
*
Documentation improved and heading styles fixed.
...
...
tex_markdown/README.md
View file @
031d4f7
...
...
@@ -5,16 +5,23 @@ This is a flutter package to create markdown widget. with Latex math formula sup
You can create simple markdown view by this package.
At this moment this package supports:
*
Unordered l
ist
-
L
ist
`* <Text here>`
*
Links
- Unordered list item
1. Ordered list item
`[<text here>](<href>)`
*
Images with size
-
Horizontal line
``
*
Table
---
-
Links
[<text here>](<href>)
-
Images with size

-
Table
```
| Name | Roll |
...
...
@@ -25,18 +32,35 @@ At this moment this package supports:
|-------------|-------------|
| sohag | 1 |
*
Bolt texts
-
Bolt text
**Bolt text**
`**<Text here>**`
*
heading texts
-
Italic text
`## <Text here>`
*
Latex formula
*Italic text*
`$\frac a b$`
-
heading texts
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
-
Latex formula $
\f
rac a b$
$\frac a b$
-
Radio button and checkbox
() Unchecked radio
(x) Checked radio
[] Unchecked checkbox
[x] Checked checkbox
## Getting started
Run this command:
...
...
tex_markdown/example/lib/main.dart
View file @
031d4f7
...
...
@@ -33,16 +33,27 @@ class MyHomePage extends StatefulWidget {
class
_MyHomePageState
extends
State
<
MyHomePage
>
{
final
TextEditingController
_controller
=
TextEditingController
(
text:
'''# hi how are you?
## hi how are you?
### hi how are you?
#### hi how are you?
##### hi how are you?
###### hi how are you?

---
**bold text**
*Italic text*
[Link]()
- unordered list
1. ordered list 1
2. ordered list 2
(x) Radio checked
() Radio unchecked
[x] checkbox checked
[] Checkbox unchecked
###### hi how are you?'''
);
| Name | Country |
| Sohag | Bangladesh |
'''
);
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
...
...
@@ -68,13 +79,17 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
ConstrainedBox
(
constraints:
const
BoxConstraints
(
maxHeight:
300
),
constraints:
const
BoxConstraints
(
maxHeight:
200
),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
TextField
(
decoration:
const
InputDecoration
(
border:
OutlineInputBorder
()),
decoration:
const
InputDecoration
(
border:
OutlineInputBorder
(),
label:
Text
(
"Type here:"
)),
maxLines:
null
,
controller:
_controller
,
),
),
),
],
),
);
...
...
tex_markdown/example/pubspec.lock
View file @
031d4f7
...
...
@@ -204,7 +204,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.
2
"
version: "0.0.
3
"
tex_text:
dependency: transitive
description:
...
...
tex_markdown/lib/md_widget.dart
View file @
031d4f7
...
...
@@ -3,9 +3,8 @@ import 'package:tex_text/tex_text.dart';
/// It creates a markdown widget closed to each other.
class
MdWidget
extends
StatelessWidget
{
MdWidget
(
String
expression
,
{
super
.
key
,
this
.
style
,
this
.
onLinkTab
,
this
.
followLinkColor
=
false
})
:
exp
=
expression
.
trim
();
const
MdWidget
(
this
.
exp
,
{
super
.
key
,
this
.
style
,
this
.
onLinkTab
,
this
.
followLinkColor
=
false
});
final
String
exp
;
final
TextStyle
?
style
;
final
Function
(
String
url
,
String
title
)?
onLinkTab
;
...
...
@@ -14,17 +13,22 @@ class MdWidget extends StatelessWidget {
Widget
build
(
BuildContext
context
)
{
final
RegExp
h
=
RegExp
(
r"^(#{1,6})\s(.*)$"
);
final
RegExp
b
=
RegExp
(
r"^\*\*([^\s].*[^\s])\*\*$"
);
final
RegExp
i
=
RegExp
(
r"^\*([^\s].*[^\s])\*$"
);
final
RegExp
a
=
RegExp
(
r"^\[([^\s].*[^\s]?)?\]\(([^\s]+)?\)$"
);
final
RegExp
img
=
RegExp
(
r"^\!\[([^\s].*[^\s]?)?\]\(([^\s]+)\)$"
);
final
RegExp
ol
=
RegExp
(
r"^\*{1}\s(.*)$"
);
final
RegExp
table
=
RegExp
(
r"^(((\|(.*)?\|)(\s?)+\n(\s?)+)+)?((\|(.*)?\|))$"
);
final
RegExp
ul
=
RegExp
(
r"^(\-)\s(.*)$"
);
final
RegExp
ol
=
RegExp
(
r"^([0-9]+.)\s(.*)$"
);
final
RegExp
rb
=
RegExp
(
r"^\((x)?\)\s(.*)$"
);
final
RegExp
cb
=
RegExp
(
r"^\[(x)?\]\s(.*)$"
);
final
RegExp
hr
=
RegExp
(
r"^(--)[-]+$"
);
final
RegExp
table
=
RegExp
(
r"^(((\|[^\n\|]+\|)((([^\n\|]+\|)+)?))(\n(((\|[^\n\|]+\|)(([^\n\|]+\|)+)?)))+)?$"
,
);
if
(
table
.
hasMatch
(
exp
))
{
final
List
<
Map
<
int
,
String
>>
value
=
exp
.
split
(
'
\n
'
)
.
map
<
Map
<
int
,
String
>>(
(
e
)
=>
e
.
trim
()
.
split
(
'|'
)
.
where
((
element
)
=>
element
.
isNotEmpty
)
.
toList
()
...
...
@@ -38,7 +42,8 @@ class MdWidget extends StatelessWidget {
}
}
if
(
maxCol
==
0
)
{
return
const
SizedBox
();
// return const SizedBox();
return
Text
(
""
,
style:
style
);
}
return
Table
(
defaultVerticalAlignment:
TableCellVerticalAlignment
.
middle
,
...
...
@@ -64,23 +69,96 @@ class MdWidget extends StatelessWidget {
}
if
(
h
.
hasMatch
(
exp
))
{
var
match
=
h
.
firstMatch
(
exp
.
trim
());
return
TexText
(
return
Column
(
children:
[
Row
(
children:
[
TexText
(
"
${match?[2]}
"
,
style:
[
Theme
.
of
(
context
).
textTheme
.
headline4
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
).
textTheme
.
headline5
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
).
textTheme
.
headline6
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
headlineLarge
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
headlineMedium
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
headlineSmall
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
titleLarge
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
titleMedium
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
).
textTheme
.
titleSmall
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
).
textTheme
.
bodySmall
?.
copyWith
(
color:
style
?.
color
),
Theme
.
of
(
context
)
.
textTheme
.
titleSmall
?.
copyWith
(
color:
style
?.
color
),
][
match
![
1
]!.
length
-
1
],
),
],
),
if
(
match
[
1
]!.
length
==
1
)
const
Divider
(
height:
6
),
],
);
}
if
(
ol
.
hasMatch
(
exp
))
{
var
match
=
ol
.
firstMatch
(
exp
.
trim
());
if
(
hr
.
hasMatch
(
exp
))
{
return
const
Divider
(
height:
5
,
);
}
if
(
cb
.
hasMatch
(
exp
))
{
var
match
=
cb
.
firstMatch
(
exp
.
trim
());
return
Row
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisSize:
MainAxisSize
.
min
,
children:
[
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
10
),
child:
Checkbox
(
// value: true,
value:
(
"
${match?[1]}
"
==
"x"
),
onChanged:
(
value
)
{},
fillColor:
ButtonStyleButton
.
allOrNull
(
style
?.
color
),
),
),
MdWidget
(
"
${match?[2]}
"
,
style:
style
,
),
],
);
}
if
(
rb
.
hasMatch
(
exp
))
{
var
match
=
rb
.
firstMatch
(
exp
.
trim
());
return
Row
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisSize:
MainAxisSize
.
min
,
children:
[
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
10
),
child:
Radio
(
value:
true
,
groupValue:
(
"
${match?[1]}
"
==
"x"
),
onChanged:
(
value
)
{},
fillColor:
ButtonStyleButton
.
allOrNull
(
style
?.
color
),
),
),
MdWidget
(
"
${match?[2]}
"
,
style:
style
,
),
],
);
}
if
(
ul
.
hasMatch
(
exp
))
{
var
match
=
ul
.
firstMatch
(
exp
.
trim
());
return
Row
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisSize:
MainAxisSize
.
max
,
...
...
@@ -90,11 +168,34 @@ class MdWidget extends StatelessWidget {
child:
Icon
(
Icons
.
circle
,
color:
style
?.
color
,
size:
12
,
size:
8
,
),
),
MdWidget
(
"
${match?[2]}
"
,
style:
style
,
),
],
);
}
if
(
ol
.
hasMatch
(
exp
))
{
var
match
=
ol
.
firstMatch
(
exp
.
trim
());
return
Row
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisSize:
MainAxisSize
.
max
,
children:
[
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
11
),
child:
Text
(
"
${match?[1]}
"
,
style:
(
style
??
const
TextStyle
())
.
copyWith
(
fontWeight:
FontWeight
.
bold
),
// color: style?.color,
// size: 12,
),
),
MdWidget
(
"
${match?[2]}
"
,
style:
style
,
),
],
...
...
@@ -108,6 +209,14 @@ class MdWidget extends StatelessWidget {
const
TextStyle
(
fontWeight:
FontWeight
.
bold
),
);
}
if
(
i
.
hasMatch
(
exp
))
{
var
match
=
i
.
firstMatch
(
exp
.
trim
());
return
TexText
(
"
${match?[1]}
"
,
style:
(
style
??
const
TextStyle
()).
copyWith
(
fontStyle:
FontStyle
.
italic
),
);
}
if
(
a
.
hasMatch
(
exp
))
{
var
match
=
a
.
firstMatch
(
exp
.
trim
());
if
(
match
?[
1
]
==
null
&&
match
?[
2
]
==
null
)
{
...
...
@@ -156,20 +265,24 @@ class MdWidget extends StatelessWidget {
),
);
}
List
<
String
>
expL
=
exp
.
split
(
'
\n
'
)
.
map
(
(
e
)
=>
e
.
trim
(),
)
.
toList
();
List
<
String
>
expL
=
exp
.
split
(
'
\n
'
);
// .map(
// (e) => e.trim(),
// )
// .toList();
bool
hasMatch
=
false
;
for
(
final
each
in
expL
)
{
if
(
a
.
hasMatch
(
each
)
||
h
.
hasMatch
(
each
)
||
b
.
hasMatch
(
each
)
||
i
.
hasMatch
(
each
)
||
h
.
hasMatch
(
each
)
||
hr
.
hasMatch
(
each
)
||
ol
.
hasMatch
(
each
)
||
rb
.
hasMatch
(
each
)
||
cb
.
hasMatch
(
each
)
||
img
.
hasMatch
(
each
)
||
o
l
.
hasMatch
(
each
))
{
u
l
.
hasMatch
(
each
))
{
hasMatch
=
true
;
}
}
...
...
@@ -177,7 +290,6 @@ class MdWidget extends StatelessWidget {
return
Wrap
(
crossAxisAlignment:
WrapCrossAlignment
.
center
,
spacing:
10
,
runSpacing:
2
,
children:
exp
.
split
(
"
\n
"
)
.
map
<
Widget
>((
e
)
=>
MdWidget
(
...
...
tex_markdown/lib/tex_markdown.dart
View file @
031d4f7
...
...
@@ -23,10 +23,13 @@ class TexMarkdown extends StatelessWidget {
return
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
data
.
split
(
"
\n\n
"
)
.
trim
()
.
split
(
RegExp
(
r"\n\n+"
),
)
.
map
<
Widget
>(
(
e
)
=>
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
padding:
const
EdgeInsets
.
all
(
4
),
child:
MdWidget
(
e
,
style:
style
,
...
...
tex_markdown/pubspec.yaml
View file @
031d4f7
name
:
tex_markdown
description
:
This package is used to create flutter widget that can render markdown and latex formulas. It is very simple to use and uses native flutter components.
version
:
0.0.
2
version
:
0.0.
3
homepage
:
https://github.com/saminsohag/flutter_packages/tree/main/tex_markdown
environment
:
...
...
Please
register
or
login
to post a comment