mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: article: show code
Closes #759 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
||||
class StyleString {
|
||||
static const double cardSpace = 8;
|
||||
static const double safeSpace = 12;
|
||||
static const BorderRadius mdRadius = BorderRadius.all(Radius.circular(10));
|
||||
static const BorderRadius mdRadius = BorderRadius.all(imgRadius);
|
||||
static const Radius imgRadius = Radius.circular(10);
|
||||
static const double aspectRatio = 16 / 10;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ class VideoCardHMemberVideo extends StatelessWidget {
|
||||
Positioned.fill(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderRadius: StyleString.mdRadius,
|
||||
color: Colors.black54,
|
||||
),
|
||||
child: Center(
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Widget videoProgressIndicator(double progress) => ClipRect(
|
||||
clipper: ProgressClipper(),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(10),
|
||||
bottomRight: Radius.circular(10),
|
||||
bottomLeft: StyleString.imgRadius,
|
||||
bottomRight: StyleString.imgRadius,
|
||||
),
|
||||
child: LinearProgressIndicator(
|
||||
minHeight: 10,
|
||||
|
||||
@@ -1114,7 +1114,7 @@ class VideoHttp {
|
||||
'csrf': Accounts.main.csrf,
|
||||
});
|
||||
if (res.data['code'] == 0) {
|
||||
if (res.data['data']['noteIds'] != null) {
|
||||
if (res.data['data']?['noteIds'] != null) {
|
||||
noteId = res.data['data']['noteIds'].first;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ class Paragraph {
|
||||
Pic? pic;
|
||||
Line? line;
|
||||
LinkCard? linkCard;
|
||||
Code? code;
|
||||
|
||||
Paragraph({
|
||||
this.align,
|
||||
@@ -16,6 +17,7 @@ class Paragraph {
|
||||
this.pic,
|
||||
this.line,
|
||||
this.linkCard,
|
||||
this.code,
|
||||
});
|
||||
|
||||
factory Paragraph.fromJson(Map<String, dynamic> json) => Paragraph(
|
||||
@@ -31,6 +33,7 @@ class Paragraph {
|
||||
linkCard: json['link_card'] == null
|
||||
? null
|
||||
: LinkCard.fromJson(json['link_card']),
|
||||
code: json['code'] == null ? null : Code.fromJson(json['code']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
@@ -41,6 +44,16 @@ class Paragraph {
|
||||
};
|
||||
}
|
||||
|
||||
class Code {
|
||||
String? content;
|
||||
String? lang;
|
||||
|
||||
Code.fromJson(Map<String, dynamic> json) {
|
||||
content = json['content'];
|
||||
lang = json['lang'];
|
||||
}
|
||||
}
|
||||
|
||||
class Ugc {
|
||||
String? cover;
|
||||
String? descSecond;
|
||||
|
||||
@@ -85,7 +85,7 @@ class RcmdStat implements BaseStat {
|
||||
class RcmdOwner extends BaseOwner {
|
||||
RcmdOwner.fromJson(Map<String, dynamic> json) {
|
||||
name = json['goto'] == 'av'
|
||||
? (json['args']?['up_name'])
|
||||
? (json['args']?['up_name'] ?? '')
|
||||
: (json['desc_button']?['text'] ?? '');
|
||||
mid = json['args']?['up_id'] ?? 0;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart'
|
||||
show SourceModel;
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
@@ -9,6 +10,9 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:re_highlight/languages/all.dart';
|
||||
import 'package:re_highlight/re_highlight.dart';
|
||||
import 'package:re_highlight/styles/all.dart';
|
||||
|
||||
Widget opusContent({
|
||||
required BuildContext context,
|
||||
@@ -95,7 +99,7 @@ Widget opusContent({
|
||||
return SelectableText.rich(
|
||||
textAlign: element.align == 1 ? TextAlign.center : null,
|
||||
TextSpan(
|
||||
children: element.text?.nodes!.map<TextSpan>((item) {
|
||||
children: element.text?.nodes?.map<TextSpan>((item) {
|
||||
if (item.rich != null) {
|
||||
return TextSpan(
|
||||
text: '\u{1F517}${item.rich?.text}',
|
||||
@@ -149,10 +153,7 @@ Widget opusContent({
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (callback != null) {
|
||||
callback(
|
||||
[element.pic!.pics!.first.url!],
|
||||
0,
|
||||
);
|
||||
callback([element.pic!.pics!.first.url!], 0);
|
||||
} else {
|
||||
context.imageView(
|
||||
initialPage: 0,
|
||||
@@ -183,8 +184,7 @@ Widget opusContent({
|
||||
|
||||
if (element.paraType == 6) {
|
||||
if (element.linkCard?.card?.ugc != null) {
|
||||
return Card(
|
||||
margin: EdgeInsets.zero,
|
||||
return Material(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(8)),
|
||||
@@ -207,7 +207,7 @@ Widget opusContent({
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
radius: 6,
|
||||
width: 65 * 16 / 10,
|
||||
width: 65 * StyleString.aspectRatio,
|
||||
height: 65,
|
||||
src: element.linkCard!.card!.ugc!.cover,
|
||||
),
|
||||
@@ -237,6 +237,32 @@ Widget opusContent({
|
||||
}
|
||||
}
|
||||
|
||||
if (element.paraType == 7) {
|
||||
final Highlight highlight = Highlight()
|
||||
..registerLanguages(builtinAllLanguages);
|
||||
final HighlightResult result = highlight.highlightAuto(
|
||||
element.code!.content!,
|
||||
element.code!.lang == 'language-clike'
|
||||
? ['c', 'java']
|
||||
: [
|
||||
element.code!.lang!
|
||||
.replaceAll('language-', '')
|
||||
.replaceAll('like', ''),
|
||||
]);
|
||||
final TextSpanRenderer renderer = TextSpanRenderer(
|
||||
const TextStyle(), builtinAllThemes['github']!);
|
||||
result.render(renderer);
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
color: Theme.of(context).colorScheme.onInverseSurface,
|
||||
),
|
||||
width: double.infinity,
|
||||
child: SelectableText.rich(renderer.span!),
|
||||
);
|
||||
}
|
||||
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
|
||||
@@ -118,7 +118,7 @@ class FavNoteItem extends StatelessWidget {
|
||||
width: constraints.maxHeight *
|
||||
StyleString.aspectRatio,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderRadius: StyleString.mdRadius,
|
||||
color: Colors.black.withOpacity(0.6),
|
||||
),
|
||||
child: SizedBox(
|
||||
|
||||
@@ -534,7 +534,7 @@ class _FavDetailPageState extends State<FavDetailPage> {
|
||||
width: constraints.maxHeight *
|
||||
StyleString.aspectRatio,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderRadius: StyleString.mdRadius,
|
||||
color: Colors.black.withOpacity(0.6),
|
||||
),
|
||||
child: SizedBox(
|
||||
|
||||
@@ -182,7 +182,7 @@ class HistoryItem extends StatelessWidget {
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderRadius: StyleString.mdRadius,
|
||||
color: Colors.black.withOpacity(0.6),
|
||||
),
|
||||
child: SizedBox(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic_badge_mode.dart';
|
||||
import 'package:PiliPlus/pages/main/index.dart';
|
||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||
@@ -52,7 +53,7 @@ class _HomePageState extends State<HomePage>
|
||||
dividerColor: Colors.transparent,
|
||||
dividerHeight: 0,
|
||||
enableFeedback: true,
|
||||
splashBorderRadius: BorderRadius.circular(10),
|
||||
splashBorderRadius: StyleString.mdRadius,
|
||||
tabAlignment: TabAlignment.center,
|
||||
onTap: (value) {
|
||||
feedBack();
|
||||
|
||||
@@ -132,7 +132,7 @@ class _LaterViewChildPageState extends State<LaterViewChildPage>
|
||||
width: constraints.maxHeight *
|
||||
StyleString.aspectRatio,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderRadius: StyleString.mdRadius,
|
||||
color: Colors.black.withOpacity(0.6),
|
||||
),
|
||||
child: SizedBox(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/avatar.dart';
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart'
|
||||
show SourceModel;
|
||||
@@ -145,8 +146,9 @@ class UserInfoCard extends StatelessWidget {
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||
color: context.vipColor),
|
||||
borderRadius: StyleString.mdRadius,
|
||||
color: context.vipColor,
|
||||
),
|
||||
child: Text(
|
||||
card.vip?.label?.text ?? '大会员',
|
||||
strutStyle: const StrutStyle(
|
||||
|
||||
@@ -564,7 +564,7 @@ class _PostPanelState extends CommonCollapseSlidePageState<PostPanel> {
|
||||
}
|
||||
} else {
|
||||
if (const [301, 302, 303, 307, 308].contains(res.statusCode)) {
|
||||
String? redirectUrl = res.headers['location']?.first;
|
||||
String? redirectUrl = res.headers['location']?.firstOrNull;
|
||||
if (redirectUrl != null) {
|
||||
_onPost(url: redirectUrl);
|
||||
return;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/pages/webdav/webdav.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -83,7 +84,7 @@ class _WebDavSettingPageState extends State<WebDavSettingPage> {
|
||||
child: FilledButton.tonal(
|
||||
style: FilledButton.styleFrom(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderRadius: StyleString.mdRadius,
|
||||
),
|
||||
),
|
||||
onPressed: WebDav().backup,
|
||||
@@ -95,7 +96,7 @@ class _WebDavSettingPageState extends State<WebDavSettingPage> {
|
||||
child: FilledButton.tonal(
|
||||
style: FilledButton.styleFrom(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderRadius: StyleString.mdRadius,
|
||||
),
|
||||
),
|
||||
onPressed: WebDav().restore,
|
||||
|
||||
@@ -25,7 +25,7 @@ class UrlUtils {
|
||||
),
|
||||
);
|
||||
if (response.statusCode == 302 || response.statusCode == 301) {
|
||||
String? redirectUrl = response.headers['location']?.first;
|
||||
String? redirectUrl = response.headers['location']?.firstOrNull;
|
||||
debugPrint('redirectUrl: $redirectUrl');
|
||||
if (redirectUrl != null) {
|
||||
if (redirectUrl.startsWith('/')) {
|
||||
|
||||
@@ -1480,6 +1480,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
re_highlight:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: re_highlight
|
||||
sha256: "6c4ac3f76f939fb7ca9df013df98526634e17d8f7460e028bd23a035870024f2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.0.3"
|
||||
rxdart:
|
||||
dependency: "direct overridden"
|
||||
description:
|
||||
|
||||
@@ -190,6 +190,7 @@ dependencies:
|
||||
synchronized: ^3.3.0
|
||||
document_file_save_plus: ^2.0.0
|
||||
webdav_client: ^1.2.2
|
||||
re_highlight: ^0.0.3
|
||||
|
||||
dependency_overrides:
|
||||
screen_brightness: ^2.0.1
|
||||
|
||||
Reference in New Issue
Block a user