saminsohag

customizable latex and workarround added

## 0.0.4
* Customizable latex and workarround added.
## 0.0.3
* Some latex related fixes.
... ...
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(
... ...
... ... @@ -182,7 +182,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.3"
version: "0.0.4"
http:
dependency: transitive
description:
... ...
... ... @@ -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 {
... ...
... ... @@ -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 InlineMd {
class LatexMathMultyLine extends BlockMd {
@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));
}
}
... ...
// 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;
// }
// }
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:
... ...