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 02:45:09 +0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
39102613f2487570fc034ad32a6e38bf259b9a30
39102613
1 parent
67e7e5e5
customizable latex and workarround added
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
56 additions
and
126 deletions
gpt_markdown/CHANGELOG.md
gpt_markdown/example/lib/main.dart
gpt_markdown/example/pubspec.lock
gpt_markdown/lib/custom_widgets/unordered_ordered_list.dart
gpt_markdown/lib/markdown_component.dart
gpt_markdown/lib/tex_text/tex_text.dart
gpt_markdown/pubspec.yaml
gpt_markdown/CHANGELOG.md
View file @
3910261
## 0.0.4
*
Customizable latex and workarround added.
## 0.0.3
*
Some latex related fixes.
...
...
gpt_markdown/example/lib/main.dart
View file @
3910261
import
'dart:developer'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_math_fork/flutter_math.dart'
;
import
'package:gpt_markdown/gpt_markdown.dart'
;
...
...
@@ -123,7 +122,8 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
Column(
children: [
Expanded(
child: ListView(
child: SingleChildScrollView(
child: Column(
children: [
AnimatedBuilder(
animation: _controller,
...
...
@@ -135,7 +135,8 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
width: 1,
color: Theme.of(context).colorScheme.outline),
),
child: LayoutBuilder(builder: (context, constraints) {
child:
LayoutBuilder(builder: (context, constraints) {
return Theme(
data: Theme.of(context).copyWith(
textTheme: const TextTheme(
...
...
@@ -167,15 +168,27 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
// Regular text font size here.
fontSize: 15,
),
latexWorkaround: (tex) => tex.replaceAllMapped(
RegExp(r"align
\
*"), (match) => "aligned"),
latexWorkaround: (tex) =>
tex.replaceAllMapped(RegExp(r"align
\
*"),
(match) => "aligned"),
latexBuilder: (contex, tex) {
return SingleChildScrollView(
var controller = ScrollController();
return Column(
children: [
Scrollbar(
controller: controller,
child: SingleChildScrollView(
controller: controller,
scrollDirection: Axis.horizontal,
child: Math.tex(
tex,
textStyle: const TextStyle(fontSize: 17),
textStyle: const TextStyle(
fontSize: 17,
),
),
),
),
],
);
},
),
...
...
@@ -188,6 +201,7 @@ Markdown and LaTeX can be powerful tools for formatting text and mathematical ex
],
),
),
),
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 200),
child: Padding(
...
...
gpt_markdown/example/pubspec.lock
View file @
3910261
...
...
@@ -182,7 +182,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.
3
"
version: "0.0.
4
"
http:
dependency: transitive
description:
...
...
gpt_markdown/lib/custom_widgets/unordered_ordered_list.dart
View file @
3910261
...
...
@@ -191,6 +191,28 @@ class UnorderedListRenderObject extends RenderProxyBox {
offset
+
_bulletOffset
,
_bulletSize
,
Paint
()..
color
=
_bulletColor
);
}
}
@override
bool
hitTestSelf
(
Offset
position
)
{
return
false
;
}
@override
bool
hitTestChildren
(
BoxHitTestResult
result
,
{
required
Offset
position
})
{
Offset
offset
=
(
child
!.
parentData
as
BoxParentData
).
offset
;
return
result
.
addWithPaintOffset
(
offset:
offset
,
position:
position
,
hitTest:
(
result
,
newOffset
)
{
return
child
?.
hitTest
(
result
,
position:
newOffset
)
??
false
;
},
);
}
@override
bool
hitTest
(
BoxHitTestResult
result
,
{
required
Offset
position
})
{
return
hitTestChildren
(
result
,
position:
position
);
}
}
class
OrderedListView
extends
SingleChildRenderObjectWidget
{
...
...
gpt_markdown/lib/markdown_component.dart
View file @
3910261
...
...
@@ -249,12 +249,6 @@ class HTag extends BlockMd {
textDirection:
textDirection
,
);
}
// @override
// String toHtml(String text) {
// var match = exp.firstMatch(text.trim());
// return "<h${match![1]!.length}>${TexText.toHtmlData(match[2].toString().trim())}<h${match[1]!.length}>";
// }
}
/// Horizontal line component
...
...
@@ -480,7 +474,7 @@ class BoldMd extends InlineMd {
}
}
class
LatexMathMultyLine
extends
Inline
Md
{
class
LatexMathMultyLine
extends
Block
Md
{
@override
RegExp
get
exp
=>
RegExp
(
r"\\\[(.*?)\\\]|(\\begin.*?\\end{.*?})"
,
...
...
@@ -488,14 +482,14 @@ class LatexMathMultyLine extends InlineMd {
);
@override
InlineSpan
span
(
Widget
build
(
BuildContext
context
,
String
text
,
TextStyle
?
style
,
TextDirection
textDirection
,
final
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
final
String
Function
(
String
tex
)?
latexWorkaround
,
final
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
void
Function
(
String
url
,
String
title
)?
onLinkTab
,
String
Function
(
String
tex
)?
latexWorkaround
,
Widget
Function
(
BuildContext
context
,
String
tex
)?
latexBuilder
,
)
{
var
p0
=
exp
.
firstMatch
(
text
.
trim
());
p0
?.
group
(
0
);
...
...
@@ -504,7 +498,7 @@ class LatexMathMultyLine extends InlineMd {
var
builder
=
latexBuilder
??
(
BuildContext
context
,
String
tex
)
=>
Math
.
tex
(
workaround
(
tex
)
,
tex
,
textStyle:
style
?.
copyWith
(
fontFamily:
"SansSerif"
,
),
...
...
@@ -540,12 +534,7 @@ class LatexMathMultyLine extends InlineMd {
);
},
);
return
WidgetSpan
(
alignment:
PlaceholderAlignment
.
baseline
,
baseline:
TextBaseline
.
alphabetic
,
child:
builder
(
context
,
mathText
),
);
return
builder
(
context
,
workaround
(
mathText
));
}
}
...
...
gpt_markdown/lib/tex_text/tex_text.dart
deleted
100644 → 0
View file @
67e7e5e
// library tex_text;
//
// import 'package:flutter/material.dart';
// import 'package:flutter_math_fork/flutter_math.dart';
//
// /// A LaTex text view.
// ///
// /// Example:
// /// ```dart
// /// TexText(r"The equation is $x^2+y^2=z^2$") //Output: The equation is <LaTex formatted equation>
// ///
// /// // \$ shows $ result
// /// TexText(r"The equation is \$") //Output: The equation is $
// /// ```
// class TexText {
// const TexText(
// this.text, {
// TextStyle? style,
// this.textDirection = TextDirection.ltr,
// this.mathStyle = MathStyle.text,
// }) : _style = style;
// final String text;
// final TextStyle? _style;
// final TextDirection textDirection;
// final MathStyle mathStyle;
// // final TexAlignment alignment;
//
// List<InlineSpan> getSpans(BuildContext context) {
// //
// String e = text;
// TextStyle? style = _style ?? Theme.of(context).textTheme.bodyMedium;
// List<InlineSpan> spans = [];
//
// e.splitMapJoin(
// RegExp(
// r"\\\[(.*?)\\\]|\\\((.*?)\\\)",
// multiLine: true,
// dotAll: true,
// ),
// onMatch: (p0) {
// spans.add(
// WidgetSpan(
// alignment: PlaceholderAlignment.baseline,
// baseline: TextBaseline.alphabetic,
// child: Math.tex(
// // _newEasySyntax(p0[1].toString().replaceAll(dollar, "\\\$")),
// p0[1]?.toString() ?? p0[2].toString(),
// textStyle: style?.copyWith(
// fontFamily: "SansSerif",
// ),
// mathStyle: mathStyle,
// 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,
// ),
// onErrorFallback: (err) {
// return Text(
// "\\(${p0[1] ?? p0[2]}\\)",
// textDirection: textDirection,
// style: style?.copyWith(
// color: Theme.of(context).colorScheme.error) ??
// TextStyle(color: Theme.of(context).colorScheme.error),
// );
// },
// ),
// ),
// );
// return p0[1].toString();
// },
// onNonMatch: (p0) {
// spans.add(
// TextSpan(
// text: p0.toString(),
// style: style,
// ),
// );
// return p0;
// },
// );
// return spans;
// }
// }
gpt_markdown/pubspec.yaml
View file @
3910261
name
:
gpt_markdown
description
:
"
The
purpose
of
this
package
is
to
render
the
response
of
ChatGPT
into
a
Flutter
app."
version
:
0.0.
3
version
:
0.0.
4
homepage
:
https://github.com/saminsohag/flutter_packages/tree/main/gpt_markdown
environment
:
...
...
Please
register
or
login
to post a comment