Skip to content

Commit 44a2f13

Browse files
修复代码高亮失效问题
1 parent 2a2cc79 commit 44a2f13

File tree

8 files changed

+41
-39
lines changed

8 files changed

+41
-39
lines changed

android/gradle.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
org.gradle.jvmargs=-Xmx1536M
22
android.enableR8=true
33
android.useAndroidX=true
4-
android.enableJetifier=true
4+
android.enableJetifier=true
5+
#systemProp.http.proxyHost=127.0.0.1
6+
#systemProp.http.proxyPort=7890
7+
#systemProp.https.proxyHost=127.0.0.1
8+
#systemProp.https.proxyPort=7890

lib/common/utils/html_utils.dart

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class HtmlUtils {
1212
String lang = 'java',
1313
userBR = true}) {
1414
String currentData = (mdData != null && !mdData.contains("<code>"))
15-
? "<body>\n<pre class=\"pre\">\n<code lang='$lang'>\n$mdData</code>\n</pre>\n</body>\n"
16-
: "<body>\n<pre class=\"pre\">\n${mdData!}</pre>\n</body>\n";
15+
? "<body>\n<pre>\n<code lang='$lang'>\n$mdData</code>\n</pre>\n</body>\n"
16+
: "<body>\n<pre>\n${mdData!}</pre>\n</body>\n";
1717
return generateHtml(currentData,
1818
backgroundColor: backgroundColor, userBR: userBR);
1919
}
@@ -101,20 +101,8 @@ class HtmlUtils {
101101
String actionColor = GSYColors.actionBlueString,
102102
userBR = true}) {
103103
// ignore: prefer_interpolation_to_compose_strings
104-
return "${"${"<html>\n" +
105-
"<head>\n" +
106-
"<meta charset=\"utf-8\" />\n" +
107-
"<title></title>\n" +
108-
"<meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;\"/>" +
109-
"<meta name=\“app-mobile-web-app-capable\” content=\“yes\" /> " +
110-
"<link href=\"https:\/\/cdn.bootcss.com/highlight.js/9.12.0/styles/dracula.min.css\" rel=\"stylesheet\">\n" +
111-
"<script src=\"https:\/\/cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js\"></script> " +
112-
"<script>hljs.configure({'useBR': ${userBR.toString()}"
113-
"});hljs.initHighlightingOnLoad();</script> " +
114-
"<style>" +
115-
"body{background: $backgroundColor"
116-
};}a {color:$actionColor !important;}.highlight pre, pre { word-wrap: ${wrap ? "break-word" : "normal"}; white-space: ${wrap ? "pre-wrap" : "pre"}; }thead, tr {background:${GSYColors.miWhiteString};}td, th {padding: 5px 10px;font-size: 12px;direction:hor}.highlight {overflow: scroll; background: ${GSYColors.miWhiteString}}tr:nth-child(even) {background:${GSYColors.primaryLightValueString};color:${GSYColors.miWhiteString};}tr:nth-child(odd) {background: ${GSYColors.miWhiteString};color:${GSYColors.primaryLightValueString};}th {font-size: 14px;color:${GSYColors.miWhiteString};background:${GSYColors.primaryLightValueString};}</style></head>\n<body>\n" +
117-
mdHTML}</body>\n</html>";
104+
return "${"${"<html>\n" + "<head>\n" + "<meta charset=\"utf-8\" />\n" + "<title></title>\n" + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\"/>" + "<meta name=\“app-mobile-web-app-capable\” content=\“yes\" /> " + "<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css\">\n" + "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js\"></script>" + "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/go.min.js\"></script>" + "<script>hljs.configure({'useBR': ${userBR.toString()}"
105+
"});hljs.initHighlightingOnLoad();</script> " + "<style>" + "body{background: $backgroundColor"};}a {color:$actionColor !important;}.highlight pre, pre { word-wrap: ${wrap ? "break-word" : "normal"}; white-space: ${wrap ? "pre-wrap" : "pre"}; }thead, tr {background:${GSYColors.miWhiteString};}td, th {padding: 5px 10px;font-size: 12px;direction:hor}.highlight {overflow: scroll; background: ${GSYColors.miWhiteString}}tr:nth-child(even) {background:${GSYColors.primaryLightValueString};color:${GSYColors.miWhiteString};}tr:nth-child(odd) {background: ${GSYColors.miWhiteString};color:${GSYColors.primaryLightValueString};}th {font-size: 14px;color:${GSYColors.miWhiteString};background:${GSYColors.primaryLightValueString};}</style></head>\n<body>\n" + mdHTML}</body>\n</html>";
118106
}
119107

120108
static parseDiffSource(String? diffSource, bool wrap) {
@@ -158,7 +146,8 @@ class HtmlUtils {
158146
lineNumberStr = getDiffLineNumber(
159147
curRemoveNumber == -1 ? "" : ("$curRemoveNumber"),
160148
curAddNumber == -1 ? "" : ("$curAddNumber"));
161-
source = "$source<div $classStr>${wrap ? "" : lineNumberStr! + getBlank(1)}$line</div>";
149+
source =
150+
"$source<div $classStr>${wrap ? "" : lineNumberStr! + getBlank(1)}$line</div>";
162151
}
163152
return source;
164153
}
@@ -213,7 +202,7 @@ class HtmlUtils {
213202
}
214203
}
215204
lang ??= defaultLang;
216-
if ('markdown' == lang) {
205+
if ('markdown' == lang || 'md' == lang) {
217206
return generateHtml(res.data, backgroundColor: GSYColors.miWhiteString);
218207
} else {
219208
return generateCode2HTml(res.data,

lib/common/utils/navigator_utils.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class NavigatorUtils {
253253
String? path,
254254
String? data,
255255
String? branch,
256+
String? lang,
256257
String? htmlUrl}) {
257258
NavigatorRouter(
258259
context,
@@ -262,6 +263,7 @@ class NavigatorUtils {
262263
reposName: reposName,
263264
path: path,
264265
data: data,
266+
lang: lang,
265267
branch: branch,
266268
htmlUrl: htmlUrl,
267269
));
@@ -275,6 +277,7 @@ class NavigatorUtils {
275277
String? path,
276278
String? data,
277279
String? branch,
280+
String? lang,
278281
String? htmlUrl}) {
279282
NavigatorUtils.gotoCodeDetailPageWeb(
280283
context,
@@ -283,6 +286,7 @@ class NavigatorUtils {
283286
userName: userName,
284287
data: data,
285288
path: path,
289+
lang: lang,
286290
branch: branch,
287291
);
288292
}

lib/page/code_detail_page_web.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ class CodeDetailPageWeb extends StatefulWidget {
2828

2929
final String? htmlUrl;
3030

31+
final String? lang;
32+
3133
const CodeDetailPageWeb(
32-
{super.key, this.title,
34+
{super.key,
35+
this.title,
3336
this.userName,
3437
this.reposName,
3538
this.path,
3639
this.data,
40+
this.lang,
3741
this.branch,
3842
this.htmlUrl});
3943

@@ -56,13 +60,14 @@ class _CodeDetailPageState extends State<CodeDetailPageWeb> {
5660

5761
Future<Uri?> _getData() async {
5862
if (widget.data != null) {
59-
return Uri.dataFromString(widget.data!);
63+
return Uri.dataFromString(widget.data!,
64+
mimeType: 'text/html', encoding: Encoding.getByName("utf-8"));
6065
}
6166
var res = await ReposRepository.getReposFileDirRequest(
6267
widget.userName, widget.reposName,
6368
path: widget.path, branch: widget.branch, text: true, isHtml: true);
6469
if (res != null && res.result) {
65-
String data2 = HtmlUtils.resolveHtmlFile(res, "java");
70+
String data2 = HtmlUtils.resolveHtmlFile(res, widget.lang ?? "java");
6671
return Uri.dataFromString(data2,
6772
mimeType: 'text/html', encoding: Encoding.getByName("utf-8"));
6873
}
@@ -84,8 +89,6 @@ class _CodeDetailPageState extends State<CodeDetailPageWeb> {
8489
title: GSYTitleBar(widget.title),
8590
),
8691
body: FutureBuilder<Uri?>(
87-
initialData:
88-
widget.data != null ? Uri.dataFromString(widget.data!) : null,
8992
future: _getData(),
9093
builder: (context, result) {
9194
if (result.data == null) {
@@ -97,11 +100,9 @@ class _CodeDetailPageState extends State<CodeDetailPageWeb> {
97100
child: Row(
98101
mainAxisAlignment: MainAxisAlignment.center,
99102
children: <Widget>[
100-
SpinKitDoubleBounce(
101-
color: Theme.of(context).primaryColor),
103+
SpinKitDoubleBounce(color: Theme.of(context).primaryColor),
102104
Container(width: 10.0),
103-
Text(
104-
GSYLocalizations.i18n(context)!.loading_text,
105+
Text(GSYLocalizations.i18n(context)!.loading_text,
105106
style: GSYConstant.middleText),
106107
],
107108
),

lib/page/push/push_detail_page.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ class _PushDetailPageState extends State<PushDetailPage>
8888
reposName: widget.reposName,
8989
userName: widget.userName,
9090
path: itemViewModel.patch,
91-
data: Uri.dataFromString(html,
92-
mimeType: 'text/html', encoding: Encoding.getByName("utf-8"))
93-
.toString(),
91+
data: html,
9492
branch: "",
9593
);
9694
});

lib/page/repos/repository_file_list_page.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,18 @@ class RepositoryDetailFileListPageState
131131
NavigatorUtils.gotoPhotoViewPage(
132132
context, "${fileItemViewModel.htmlUrl!}?raw=true");
133133
} else {
134+
String? lang;
135+
var typeIndex = fileItemViewModel.name!.lastIndexOf(".");
136+
if(typeIndex != -1) {
137+
lang = fileItemViewModel.name!.substring(typeIndex + 1);
138+
}
134139
NavigatorUtils.gotoCodeDetailPlatform(
135140
context,
136141
title: fileItemViewModel.name,
137142
reposName: provider.reposName,
138143
userName: provider.userName,
139144
path: path,
145+
lang: lang,
140146
branch: context.read<ReposDetailProvider>().currentBranch,
141147
);
142148
}

pubspec.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,18 +1383,18 @@ packages:
13831383
dependency: "direct main"
13841384
description:
13851385
name: webview_flutter
1386-
sha256: "6869c8786d179f929144b4a1f86e09ac0eddfe475984951ea6c634774c16b522"
1386+
sha256: "889a0a678e7c793c308c68739996227c9661590605e70b1f6cf6b9a6634f7aec"
13871387
url: "https://pub.flutter-io.cn"
13881388
source: hosted
1389-
version: "4.8.0"
1389+
version: "4.10.0"
13901390
webview_flutter_android:
13911391
dependency: "direct main"
13921392
description:
13931393
name: webview_flutter_android
1394-
sha256: c66651fba15f9d7ddd31daec42da8d6bce46c85610a7127e3ebcb39a4395c3c9
1394+
sha256: e09150b28a07933839adef0e4a088bb43e8c8d9e6b93025b01882d4067a58ab0
13951395
url: "https://pub.flutter-io.cn"
13961396
source: hosted
1397-
version: "3.16.6"
1397+
version: "4.3.4"
13981398
webview_flutter_platform_interface:
13991399
dependency: transitive
14001400
description:
@@ -1407,10 +1407,10 @@ packages:
14071407
dependency: "direct main"
14081408
description:
14091409
name: webview_flutter_wkwebview
1410-
sha256: "9c62cc46fa4f2d41e10ab81014c1de470a6c6f26051a2de32111b2ee55287feb"
1410+
sha256: c49a98510080378b1525132f407a92c3dcd3b7145bef04fb8137724aadcf1cf0
14111411
url: "https://pub.flutter-io.cn"
14121412
source: hosted
1413-
version: "3.14.0"
1413+
version: "3.18.4"
14141414
win32:
14151415
dependency: transitive
14161416
description:
@@ -1453,4 +1453,4 @@ packages:
14531453
version: "3.1.2"
14541454
sdks:
14551455
dart: ">=3.7.0-0 <4.0.0"
1456-
flutter: ">=3.24.0"
1456+
flutter: ">=3.27.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dependencies:
4343
dio: 5.6.0
4444
#fconsole: 2.2.1
4545
path_provider: 2.1.4
46-
webview_flutter: 4.8.0
46+
webview_flutter: 4.10.0
4747
# 高版本目前和👆兼容有问题
4848
flutter_inappwebview: 6.1.0+1
4949
#bezier: ^1.1.5

0 commit comments

Comments
 (0)