span method
Implementation
@override
InlineSpan span(
BuildContext context,
String text,
final GptMarkdownConfig config,
) {
var p0 = exp.firstMatch(text.trim());
p0?.group(0);
String mathText = p0?[1]?.toString() ?? "";
var workaround = config.latexWorkaround ?? (String tex) => tex;
var builder = config.latexBuilder ??
(BuildContext context, String tex, TextStyle textStyle, bool inline) =>
Math.tex(
tex,
textStyle: textStyle,
mathStyle: MathStyle.display,
textScaleFactor: 1,
settings: const TexParserSettings(
strict: Strict.ignore,
),
options: MathOptions(
sizeUnderTextStyle: MathSize.large,
color: config.style?.color ??
Theme.of(context).colorScheme.onSurface,
fontSize: config.style?.fontSize ??
Theme.of(context).textTheme.bodyMedium?.fontSize,
mathFontOptions: FontOptions(
fontFamily: "Main",
fontWeight: config.style?.fontWeight ?? FontWeight.normal,
fontShape: FontStyle.normal,
),
textFontOptions: FontOptions(
fontFamily: "Main",
fontWeight: config.style?.fontWeight ?? FontWeight.normal,
fontShape: FontStyle.normal,
),
style: MathStyle.display,
),
onErrorFallback: (err) {
return Text(
workaround(mathText),
textDirection: config.textDirection,
style: textStyle.copyWith(
color: (!kDebugMode)
? null
: Theme.of(context).colorScheme.error),
);
},
);
return WidgetSpan(
alignment: PlaceholderAlignment.baseline,
baseline: TextBaseline.alphabetic,
child: builder(context, workaround(mathText),
config.style ?? const TextStyle(), true),
);
}