elysia/lib/plugin/MarkdownSelectableText.dart
2025-11-04 09:53:47 +08:00

59 lines
1.4 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:markdown_widget/widget/markdown_block.dart';
import 'package:markdown_widget/markdown_widget.dart';
class MarkdownSelectableText extends StatelessWidget {
final String data;
final TextStyle style;
const MarkdownSelectableText(
this.data, {
Key? key,
TextStyle? style,
}) : style = style ?? const TextStyle(),
super(key: key);
@override
Widget build(BuildContext context) {
return MarkdownBlock(
data: data,
selectable: true,
config: MarkdownConfig(configs:
[
// 段落
PConfig(textStyle:style),
// 标题 H1..H6保留原始大小/粗细,但强制颜色)
H1Config(style: style),
H2Config(style: style),
H3Config(style: style),
H4Config(style: style),
H5Config(style: style),
H6Config(style: style),
// 链接(去掉下划线的话加 decoration: TextDecoration.none
LinkConfig(style: style),
// 行内代码 / 代码块
CodeConfig(style: style),
PreConfig(
textStyle: style,
styleNotMatched:style,
),
// 引用块:它用单独的 textColor 字段
BlockquoteConfig(textColor: style.color??Colors.black),
// 表格头/体
TableConfig(headerStyle: style, bodyStyle: style),
]),
);
}
}