html shown as plain text now
This commit is contained in:
parent
efc70fde5a
commit
19fd8bb68b
|
@ -152,7 +152,7 @@ class _PostBodyState extends State<PostBody> {
|
|||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
PostTextRenderer(htmlRef: widget.content),
|
||||
PostTextRenderer(htmlInput: widget.content),
|
||||
MediaAttachments(models: widget.media),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -1,33 +1,17 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:html/parser.dart';
|
||||
|
||||
class PostTextRenderer extends StatelessWidget {
|
||||
const PostTextRenderer({
|
||||
required this.html,
|
||||
required this.htmlInput,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
final String html;
|
||||
final String htmlInput;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String text = html;
|
||||
text = handleParagraph(html);
|
||||
text = handleBreak(text);
|
||||
return SelectableText.rich(TextSpan(text: text, children: []));
|
||||
var document = parse(htmlInput);
|
||||
return SelectableText.rich(
|
||||
TextSpan(text: document.body?.text, children: []));
|
||||
}
|
||||
}
|
||||
|
||||
String handleParagraph(String input) {
|
||||
RegExp opening = RegExp(r"<p>");
|
||||
RegExp closing = RegExp(r"</p>");
|
||||
|
||||
String out = input.replaceAll(closing, "\n\n").replaceAll(opening, "");
|
||||
if (out.endsWith("\n\n")) {
|
||||
out = out.substring(0, out.length - 2);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
String handleBreak(String input) {
|
||||
return input.replaceAll("<br>", "\n");
|
||||
}
|
||||
|
|
14
pubspec.lock
14
pubspec.lock
|
@ -43,6 +43,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.16.0"
|
||||
csslib:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: csslib
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.17.2"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -98,6 +105,13 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
html:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: html
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.15.0"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
@ -42,6 +42,7 @@ dependencies:
|
|||
intl: ^0.17.0
|
||||
url_launcher: ^6.1.4
|
||||
shelf: ^1.3.1
|
||||
html: ^0.15.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in New Issue