Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: deprecate third party markdown (#6794)
Richard Shiue9138787f86aa
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dartindex 48626b4895..3f7a429c0e 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart@@ -3,46 +3,30 @@ import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.import 'package:appflowy/plugins/document/presentation/editor_configuration.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';import 'package:appflowy/shared/markdown_to_document.dart';-import 'package:appflowy/util/theme_extension.dart';import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';import 'package:appflowy_editor/appflowy_editor.dart';import 'package:easy_localization/easy_localization.dart';-import 'package:flowy_infra/theme_extension.dart';import 'package:flutter/material.dart';import 'package:flutter_bloc/flutter_bloc.dart';-import 'package:markdown_widget/markdown_widget.dart';import '../chat_editor_style.dart';-import 'selectable_highlight.dart';-enum AIMarkdownType {- appflowyEditor,- markdownWidget,-}--// Wrap the appflowy_editor or markdown_widget as a chat text message widget+// Wrap the appflowy_editor as a chat text message widgetclass AIMarkdownText extends StatelessWidget {const AIMarkdownText({super.key,required this.markdown,- this.type = AIMarkdownType.appflowyEditor,});final String markdown;- final AIMarkdownType type;@overrideWidget build(BuildContext context) {- switch (type) {- case AIMarkdownType.appflowyEditor:- return BlocProvider(- create: (context) => DocumentPageStyleBloc(view: ViewPB())- ..add(const DocumentPageStyleEvent.initial()),- child: _AppFlowyEditorMarkdown(markdown: markdown),- );- case AIMarkdownType.markdownWidget:- return _ThirdPartyMarkdown(markdown: markdown);- }+ return BlocProvider(+ create: (context) => DocumentPageStyleBloc(view: ViewPB())+ ..add(const DocumentPageStyleEvent.initial()),+ child: _AppFlowyEditorMarkdown(markdown: markdown),+ );}}@@ -147,248 +131,3 @@ class _AppFlowyEditorMarkdownState extends State<_AppFlowyEditorMarkdown> {return editorState;}}--class _ThirdPartyMarkdown extends StatelessWidget {- const _ThirdPartyMarkdown({- required this.markdown,- });-- final String markdown;-- @override- Widget build(BuildContext context) {- return MarkdownWidget(- data: markdown,- shrinkWrap: true,- physics: const NeverScrollableScrollPhysics(),- config: configFromContext(context),- );- }-- MarkdownConfig configFromContext(BuildContext context) {- return MarkdownConfig(- configs: [- HrConfig(color: AFThemeExtension.of(context).textColor),- _ChatH1Config(- style: TextStyle(- color: AFThemeExtension.of(context).textColor,- fontSize: 24,- fontWeight: FontWeight.bold,- height: 1.5,- ),- dividerColor: AFThemeExtension.of(context).lightGreyHover,- ),- _ChatH2Config(- style: TextStyle(- color: AFThemeExtension.of(context).textColor,- fontSize: 20,- fontWeight: FontWeight.bold,- height: 1.5,- ),- dividerColor: AFThemeExtension.of(context).lightGreyHover,- ),- _ChatH3Config(- style: TextStyle(- color: AFThemeExtension.of(context).textColor,- fontSize: 18,- fontWeight: FontWeight.bold,- height: 1.5,- ),- dividerColor: AFThemeExtension.of(context).lightGreyHover,- ),- H4Config(- style: TextStyle(- color: AFThemeExtension.of(context).textColor,- fontSize: 16,- fontWeight: FontWeight.bold,- height: 1.5,- ),- ),- H5Config(- style: TextStyle(- color: AFThemeExtension.of(context).textColor,- fontSize: 14,- fontWeight: FontWeight.bold,- height: 1.5,- ),- ),- H6Config(- style: TextStyle(- color: AFThemeExtension.of(context).textColor,- fontSize: 12,- fontWeight: FontWeight.bold,- height: 1.5,- ),- ),- PreConfig(- builder: (code, language) {- return ConstrainedBox(- constraints: const BoxConstraints(- minWidth: 800,- ),- child: ClipRRect(- borderRadius: const BorderRadius.all(Radius.circular(6.0)),- child: SelectableHighlightView(- code,- language: language,- theme: getHighlightTheme(context),- padding: const EdgeInsets.all(14),- textStyle: TextStyle(- color: AFThemeExtension.of(context).textColor,- fontSize: 14,- fontWeight: FontWeight.bold,- height: 1.5,- ),- ),- ),- );- },- ),- PConfig(- textStyle: TextStyle(- color: AFThemeExtension.of(context).textColor,- fontSize: 16,- fontWeight: FontWeight.w500,- height: 1.5,- ),- ),- CodeConfig(- style: TextStyle(- color: AFThemeExtension.of(context).textColor,- fontSize: 16,- fontWeight: FontWeight.w500,- height: 1.5,- ),- ),- BlockquoteConfig(- sideColor: AFThemeExtension.of(context).lightGreyHover,- textColor: AFThemeExtension.of(context).textColor,- ),- ],- );- }-- Map<String, TextStyle> getHighlightTheme(BuildContext context) {- return {- 'root': TextStyle(- color: const Color(0xffabb2bf),- backgroundColor:- Theme.of(context).isLightMode ? Colors.white : Colors.black38,- ),- 'comment': const TextStyle(- color: Color(0xff5c6370),- fontStyle: FontStyle.italic,- ),- 'quote': const TextStyle(- color: Color(0xff5c6370),- fontStyle: FontStyle.italic,- ),- 'doctag': const TextStyle(color: Color(0xffc678dd)),- 'keyword': const TextStyle(color: Color(0xffc678dd)),- 'formula': const TextStyle(color: Color(0xffc678dd)),- 'section': const TextStyle(color: Color(0xffe06c75)),- 'name': const TextStyle(color: Color(0xffe06c75)),- 'selector-tag': const TextStyle(color: Color(0xffe06c75)),- 'deletion': const TextStyle(color: Color(0xffe06c75)),- 'subst': const TextStyle(color: Color(0xffe06c75)),- 'literal': const TextStyle(color: Color(0xff56b6c2)),- 'string': const TextStyle(color: Color(0xff98c379)),- 'regexp': const TextStyle(color: Color(0xff98c379)),- 'addition': const TextStyle(color: Color(0xff98c379)),- 'attribute': const TextStyle(color: Color(0xff98c379)),- 'meta-string': const TextStyle(color: Color(0xff98c379)),- 'built_in': const TextStyle(color: Color(0xffe6c07b)),- 'attr': const TextStyle(color: Color(0xffd19a66)),- 'variable': const TextStyle(color: Color(0xffd19a66)),- 'template-variable': const TextStyle(color: Color(0xffd19a66)),- 'type': const TextStyle(color: Color(0xffd19a66)),- 'selector-class': const TextStyle(color: Color(0xffd19a66)),- 'selector-attr': const TextStyle(color: Color(0xffd19a66)),- 'selector-pseudo': const TextStyle(color: Color(0xffd19a66)),- 'number': const TextStyle(color: Color(0xffd19a66)),- 'symbol': const TextStyle(color: Color(0xff61aeee)),- 'bullet': const TextStyle(color: Color(0xff61aeee)),- 'link': const TextStyle(color: Color(0xff61aeee)),- 'meta': const TextStyle(color: Color(0xff61aeee)),- 'selector-id': const TextStyle(color: Color(0xff61aeee)),- 'title': const TextStyle(color: Color(0xff61aeee)),- 'emphasis': const TextStyle(fontStyle: FontStyle.italic),- 'strong': const TextStyle(fontWeight: FontWeight.bold),- };- }-}--class _ChatH1Config extends HeadingConfig {- const _ChatH1Config({- this.style = const TextStyle(- fontSize: 32,- height: 40 / 32,- fontWeight: FontWeight.bold,- ),- required this.dividerColor,- });-- @override- final TextStyle style;- final Color dividerColor;-- @override- String get tag => MarkdownTag.h1.name;-- @override- HeadingDivider? get divider => HeadingDivider(- space: 10,- color: dividerColor,- height: 10,- );-}--///config class for h2-class _ChatH2Config extends HeadingConfig {- const _ChatH2Config({- this.style = const TextStyle(- fontSize: 24,- height: 30 / 24,- fontWeight: FontWeight.bold,- ),- required this.dividerColor,- });- @override- final TextStyle style;- final Color dividerColor;-- @override- String get tag => MarkdownTag.h2.name;-- @override- HeadingDivider? get divider => HeadingDivider(- space: 10,- color: dividerColor,- height: 10,- );-}--class _ChatH3Config extends HeadingConfig {- const _ChatH3Config({- this.style = const TextStyle(- fontSize: 24,- height: 30 / 24,- fontWeight: FontWeight.bold,- ),- required this.dividerColor,- });-- @override- final TextStyle style;- final Color dividerColor;-- @override- String get tag => MarkdownTag.h3.name;-- @override- HeadingDivider? get divider => HeadingDivider(- space: 10,- color: dividerColor,- height: 10,- );-}diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/selectable_highlight.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/selectable_highlight.dartdeleted file mode 100644index 1452f5af8c..0000000000--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/selectable_highlight.dart+++ /dev/null@@ -1,92 +0,0 @@-import 'package:flutter/material.dart';-import 'package:highlight/highlight.dart';--/// Highlight Flutter Widget-class SelectableHighlightView extends StatelessWidget {- SelectableHighlightView(- String input, {- super.key,- this.language,- this.theme = const {},- this.padding,- this.textStyle,- int tabSize = 8,- }) : source = input.replaceAll('\t', ' ' * tabSize);-- /// The original code to be highlighted- final String source;-- /// Highlight language- ///- /// It is recommended to give it a value for performance- ///- /// [All available languages](https://github.com/pd4d10/highlight/tree/master/highlight/lib/languages)- final String? language;-- /// Highlight theme- ///- /// [All available themes](https://github.com/pd4d10/highlight/blob/master/flutter_highlight/lib/themes)- final Map<String, TextStyle> theme;-- /// Padding- final EdgeInsetsGeometry? padding;-- /// Text styles- ///- /// Specify text styles such as font family and font size- final TextStyle? textStyle;-- List<TextSpan> _convert(List<Node> nodes) {- final List<TextSpan> spans = [];- var currentSpans = spans;- final List<List<TextSpan>> stack = [];-- // ignore: always_declare_return_types- traverse(Node node) {- if (node.value != null) {- currentSpans.add(- node.className == null- ? TextSpan(text: node.value)- : TextSpan(text: node.value, style: theme[node.className!]),- );- } else if (node.children != null) {- final List<TextSpan> tmp = [];- currentSpans- .add(TextSpan(children: tmp, style: theme[node.className!]));- stack.add(currentSpans);- currentSpans = tmp;-- for (final n in node.children!) {- traverse(n);- if (n == node.children!.last) {- currentSpans = stack.isEmpty ? spans : stack.removeLast();- }- }- }- }-- for (final node in nodes) {- traverse(node);- }-- return spans;- }-- static const _rootKey = 'root';- static const _defaultBackgroundColor = Color(0xffffffff);-- @override- Widget build(BuildContext context) {- return Container(- color: theme[_rootKey]?.backgroundColor ?? _defaultBackgroundColor,- padding: padding,- child: SelectableText.rich(- TextSpan(- style: textStyle,- children:- _convert(highlight.parse(source, language: language).nodes!),- ),- ),- );- }-}