[BUG]Underlines not Shown in <u> </u>
Describe the bug:
The in the <u></u> tag cannot be seen properly.
-
HTML passed to the data of Html widget:
'<u> </u>'Nothing will show. -
HTML passed to the data of Html widget:
'<u>test </u>' -
HTML passed to the data of Html widget:
'test<u> </u>' -
HTML passed to the data of Html widget:
'test<u> </u>test'
HTML to reproduce the issue:
As stated above.
Html widget configuration:
class MyHtmlText extends StatelessWidget {
String text;
final TextStyle textStyle;
MyHtmlText({
required this.text,
required this.textStyle,
});
/// replace all ' ' and ' ' with '_'
String replaceUnderlines(String htmlText) {
return htmlText.replaceAllMapped(RegExp(r'<u>(?: |\s)*<\/u>'),
(match) {
String content = match.group(0)!; // 获取<u>标签内部的内容( 和空格)
int underscoreCount =
content.trim().replaceAll(' ', ' ').length; // 计算下划线的数量
return '_' * underscoreCount; // 返回相应数量的下划线
});
}
@override
Widget build(BuildContext context) {
// text = replaceUnderlines(text);
print(text);
return Container(
padding: EdgeInsets.all(0),
child: Html(
data: text,
style: {
"text": Style(),
"body": Style(
margin: Margins.all(0),
padding: HtmlPaddings.all(0),
fontSize: FontSize(textStyle.fontSize!),
lineHeight: LineHeight(textStyle.height),
),
"p": Style(
fontSize: FontSize(textStyle.fontSize!),
lineHeight: LineHeight(textStyle.height),
),
"h5": Style(
fontSize: FontSize(textStyle.fontSize! - 4.sp),
fontWeight: FontWeight.bold,
lineHeight: LineHeight(textStyle.height),
),
"h4": Style(
fontSize: FontSize(textStyle.fontSize!),
fontWeight: FontWeight.bold,
lineHeight: LineHeight(textStyle.height),
),
"h3": Style(
fontSize: FontSize(textStyle.fontSize! + 2.sp),
fontWeight: FontWeight.bold,
lineHeight: LineHeight(textStyle.height),
),
"h2": Style(
fontSize: FontSize(textStyle.fontSize! + 8.sp),
fontWeight: FontWeight.bold,
lineHeight: LineHeight(textStyle.height),
),
"h1": Style(
fontSize: FontSize(textStyle.fontSize! + 16.sp),
fontWeight: FontWeight.bold,
lineHeight: LineHeight(textStyle.height),
),
},
),
);
}
}
Expected behavior:
The in the <u> tag can be shown properly as the case in the browser.
Device details and Flutter/Dart/flutter_html versions:
Flutter 3.7.12 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 4d9e56e694 (4 months ago) • 2023-04-17 21:47:46 -0400
Engine • revision 1a65d409c7
Tools • Dart 2.19.6 • DevTools 2.20.1
Additional info:
I temporarily use Regular Expression to handle the raw string contents of this issue.
/// replace all ' ' and ' ' with '_'
String replaceUnderlines(String htmlText) {
return htmlText.replaceAllMapped(RegExp(r'<u>(?: |\s)*<\/u>'),
(match) {
String content = match.group(0)!; // get the contents in tag <u>( and white space)
int underscoreCount =
content.trim().replaceAll(' ', ' ').length; // calculate the number of underscore
return '_' * underscoreCount;
});
}
A picture of a cute animal (not mandatory but encouraged)
Then wrap them with
<u> </u>
Then wrap them with
<u> </u>
Yeah, it works. But maybe it's not reasonable for the users of this lib to consider this.