Skip to content

Commit

Permalink
remove any extra blank from post html
Browse files Browse the repository at this point in the history
  • Loading branch information
kidozh committed Aug 28, 2024
1 parent a7fcfca commit 396e656
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/page/ViewHistoryPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ class ViewHistoryState extends State<ViewHistoryStateWidget>{
title: Text(S.of(context).viewHistory),
automaticallyImplyLeading: true,
trailingActions: [
PlatformIconButton(
IconButton(
onPressed: () {
VibrationUtils.vibrateWithClickIfPossible();
_showDeleteAllDialog(context);
},
//label: S.of(context).clearAllViewHistories,
icon: Icon(PlatformIcons(context).deleteSolid),
icon: Icon(AppPlatformIcons(context).deleteSolid, size: isCupertino(context)? 24: null,),
)
],
),
Expand Down
2 changes: 2 additions & 0 deletions lib/utility/AppPlatformIcons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,6 @@ class AppPlatformIcons{
IconData get advertisementExemptSolid => isMaterial(context)? Icons.card_giftcard : CupertinoIcons.minus_slash_plus;

IconData get advertisementExemptCheckSolid => isMaterial(context)? Icons.verified : CupertinoIcons.checkmark_seal_fill;

IconData get deleteSolid => isMaterial(context)? Icons.delete_forever : CupertinoIcons.delete_left_fill;
}
3 changes: 1 addition & 2 deletions lib/utility/UserPreferencesUtils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ class UserPreferencesUtils{
SharedPreferences prefs = await SharedPreferences.getInstance();
String dynamicVariantString = "totalSpot";
switch (dynamicVariant){

case DynamicSchemeVariant.tonalSpot:{
dynamicVariantString = "totalSpot";
break;
Expand Down Expand Up @@ -551,7 +550,7 @@ class UserPreferencesUtils{
case "rainbow" : return DynamicSchemeVariant.rainbow;
case "fruitSalad" : return DynamicSchemeVariant.fruitSalad;
default:
return DynamicSchemeVariant.fidelity;
return DynamicSchemeVariant.tonalSpot;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/widget/DiscuzNotificationAppbarIconWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DiscuzNotificationAppbarIconWidget extends StatelessWidget{
icon: Badge.count(
count: discuzNotification.noticeCount.newprompt + discuzNotification.noticeCount.newmypost,
alignment: AlignmentDirectional.topEnd,
child: Icon(AppPlatformIcons(context).notificationSolid),
child: Icon(AppPlatformIcons(context).notificationSolid, size: isCupertino(context)? 18 : 24,),
),
onPressed: () async {
// go to notification
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/ForumThreadWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ class ForumThreadState extends State<ForumThreadStatefulWidget>{
text: shortReply.author,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.secondary,
color: Theme.of(context).colorScheme.onSecondaryContainer,
)),
TextSpan(text: ': '),
TextSpan(
Expand Down
25 changes: 21 additions & 4 deletions lib/widget/PostWidget.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import 'dart:developer';

import 'package:dio/dio.dart';
import 'package:discuz_flutter/JsonResult/ViewThreadResult.dart';
import 'package:discuz_flutter/client/MobileApiClient.dart';
Expand Down Expand Up @@ -277,7 +279,7 @@ class PostState extends State<PostStatefulWidget> {

Widget getPostContent(BuildContext context, bool compactParagraph) {
String _html = _post.message;

log("Original HTML ${_html}");

if (this.isFontStyleIgnored()) {
// regex
Expand All @@ -290,16 +292,30 @@ class PostState extends State<PostStatefulWidget> {
_html = PostTextUtils.decodePostMessage(_html);
}


if(compactParagraph){
_html = _html.replaceAll(RegExp("[\r\n]+"), "");
_html = _html
.replaceAll(RegExp(r"<br.?/>[(<br.?/>)]+", multiLine: true), "<br />")
.replaceAll(RegExp(r"<br.?/>(<br.?/>)+", multiLine: true), "<br />")
//.replaceAll(RegExp(r"\s+$"), "")
//.replaceAll(RegExp(r"[(<br.?/>)]+$"), "")
;
_html = _html.replaceAll(RegExp(r"(<br />)+$"), "");

_html = _html.replaceAllMapped(RegExp("<br\\W+/>"), (match){
print("match! ${match.group(0)} ${match.end} ${_html.length}");
if(_html.length - match.end < 3){
return "";
}
else{
return "<br />";
}
});

// _html = _html.replaceAll(RegExp(r"<br.?/>$"), "");
_html = _html.replaceAll(RegExp(r"\s+$"), "");
}

log("AFTER HTML ${_html}");


return Column(
Expand Down Expand Up @@ -329,6 +345,7 @@ class PostState extends State<PostStatefulWidget> {
),
if (_post.attachmentMapper.isNotEmpty)
ListView.builder(
padding: EdgeInsets.zero,
itemBuilder: (context, index) {
Attachment attachment = _post.getAttachmentList()[index];
return AttachmentWidget(_discuz, attachment);
Expand All @@ -344,7 +361,7 @@ class PostState extends State<PostStatefulWidget> {
padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 4.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
color: Theme.of(context).disabledColor.withOpacity(0.04),
color: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.1),
// boxShadow: [
// if(isMaterial(context))
// BoxShadow(
Expand Down

0 comments on commit 396e656

Please sign in to comment.