refactor(markdown): Replace markdown library with gpt_markdown and update styling
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../theme/theme_extensions.dart';
|
|
||||||
import 'markdown_config.dart';
|
import 'markdown_config.dart';
|
||||||
import 'markdown_preprocessor.dart';
|
import 'markdown_preprocessor.dart';
|
||||||
|
|
||||||
@@ -70,71 +69,62 @@ class StreamingMarkdownWidget extends StatelessWidget {
|
|||||||
specialBlocks.sort((a, b) => a.start.compareTo(b.start));
|
specialBlocks.sort((a, b) => a.start.compareTo(b.start));
|
||||||
|
|
||||||
Widget buildMarkdown(String data) {
|
Widget buildMarkdown(String data) {
|
||||||
return ConduitMarkdown.buildBlock(
|
return ConduitMarkdown.build(
|
||||||
context: context,
|
context: context,
|
||||||
data: data,
|
data: data,
|
||||||
onTapLink: onTapLink,
|
onTapLink: onTapLink,
|
||||||
selectable: false,
|
|
||||||
imageBuilderOverride: imageBuilderOverride,
|
imageBuilderOverride: imageBuilderOverride,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget result;
|
||||||
|
|
||||||
if (specialBlocks.isEmpty) {
|
if (specialBlocks.isEmpty) {
|
||||||
return SelectionArea(
|
result = buildMarkdown(normalized);
|
||||||
child: Theme(
|
} else {
|
||||||
data: Theme.of(context).copyWith(
|
final children = <Widget>[];
|
||||||
textSelectionTheme: TextSelectionThemeData(
|
var currentIndex = 0;
|
||||||
cursorColor: context.conduitTheme.buttonPrimary,
|
for (final block in specialBlocks) {
|
||||||
),
|
// Skip overlapping blocks
|
||||||
),
|
if (block.start < currentIndex) continue;
|
||||||
child: buildMarkdown(normalized),
|
|
||||||
),
|
final before = normalized.substring(currentIndex, block.start);
|
||||||
|
if (before.trim().isNotEmpty) {
|
||||||
|
children.add(buildMarkdown(before));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (block.type) {
|
||||||
|
case _BlockType.mermaid:
|
||||||
|
children.add(
|
||||||
|
ConduitMarkdown.buildMermaidBlock(context, block.content),
|
||||||
|
);
|
||||||
|
case _BlockType.chartJs:
|
||||||
|
children.add(
|
||||||
|
ConduitMarkdown.buildChartJsBlock(context, block.content),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentIndex = block.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
final tail = normalized.substring(currentIndex);
|
||||||
|
if (tail.trim().isNotEmpty) {
|
||||||
|
children.add(buildMarkdown(tail));
|
||||||
|
}
|
||||||
|
|
||||||
|
result = Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: children,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final children = <Widget>[];
|
// Only wrap in SelectionArea when not streaming to avoid concurrent
|
||||||
var currentIndex = 0;
|
// modification errors in Flutter's selection system during rapid updates
|
||||||
for (final block in specialBlocks) {
|
if (isStreaming) {
|
||||||
// Skip overlapping blocks
|
return result;
|
||||||
if (block.start < currentIndex) continue;
|
|
||||||
|
|
||||||
final before = normalized.substring(currentIndex, block.start);
|
|
||||||
if (before.trim().isNotEmpty) {
|
|
||||||
children.add(buildMarkdown(before));
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (block.type) {
|
|
||||||
case _BlockType.mermaid:
|
|
||||||
children.add(
|
|
||||||
ConduitMarkdown.buildMermaidBlock(context, block.content),
|
|
||||||
);
|
|
||||||
case _BlockType.chartJs:
|
|
||||||
children.add(
|
|
||||||
ConduitMarkdown.buildChartJsBlock(context, block.content),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentIndex = block.end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final tail = normalized.substring(currentIndex);
|
return SelectionArea(child: result);
|
||||||
if (tail.trim().isNotEmpty) {
|
|
||||||
children.add(buildMarkdown(tail));
|
|
||||||
}
|
|
||||||
|
|
||||||
return SelectionArea(
|
|
||||||
child: Theme(
|
|
||||||
data: Theme.of(context).copyWith(
|
|
||||||
textSelectionTheme: TextSelectionThemeData(
|
|
||||||
cursorColor: context.conduitTheme.buttonPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: children,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
pubspec.lock
16
pubspec.lock
@@ -539,14 +539,6 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
flutter_markdown_plus:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: flutter_markdown_plus
|
|
||||||
sha256: "7f349c075157816da399216a4127096108fd08e1ac931e34e72899281db4113c"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.5"
|
|
||||||
flutter_math_fork:
|
flutter_math_fork:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -701,6 +693,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "17.0.0"
|
version: "17.0.0"
|
||||||
|
gpt_markdown:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: gpt_markdown
|
||||||
|
sha256: "8174983f2ed7d8576d25810913e3afe3f8ffdaa3172c0c823b7cfc289b67f380"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.4"
|
||||||
graphs:
|
graphs:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ dependencies:
|
|||||||
|
|
||||||
# UI Components - Markdown Rendering
|
# UI Components - Markdown Rendering
|
||||||
cached_network_image: ^3.3.1
|
cached_network_image: ^3.3.1
|
||||||
flutter_markdown_plus: ^1.0.5
|
gpt_markdown: ^1.1.4
|
||||||
|
flutter_math_fork: ^0.7.2
|
||||||
markdown: ^7.3.0
|
markdown: ^7.3.0
|
||||||
webview_flutter: ^4.7.0
|
webview_flutter: ^4.7.0
|
||||||
socket_io_client: ^3.1.2
|
socket_io_client: ^3.1.2
|
||||||
yaml: ^3.1.2
|
yaml: ^3.1.2
|
||||||
flutter_math_fork: ^0.7.4
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user