Skip to content

Commit

Permalink
Merge pull request #41 from YinRenjie1993/githubapp
Browse files Browse the repository at this point in the history
代码高亮
  • Loading branch information
CarGuo authored Aug 28, 2018
2 parents 8cca604 + ae29466 commit 4dad047
Show file tree
Hide file tree
Showing 4 changed files with 503 additions and 97 deletions.
30 changes: 18 additions & 12 deletions lib/widget/GSYMarkdownWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
import 'package:gsy_github_app_flutter/widget/syntax_highlighter.dart';

/**
* 代码详情
Expand All @@ -23,23 +24,26 @@ class GSYMarkdownWidget extends StatelessWidget {
GSYMarkdownWidget({this.markdownData = "", this.style = DARK_WHITE});

_getCommonSheet(BuildContext context, Color codeBackground) {
MarkdownStyleSheet markdownStyleSheet = MarkdownStyleSheet.fromTheme(Theme.of(context));
MarkdownStyleSheet markdownStyleSheet =
MarkdownStyleSheet.fromTheme(Theme.of(context));
return markdownStyleSheet
.copyWith(
codeblockDecoration: new BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(4.0)),
color: codeBackground,
border: new Border.all(color: Color(GSYColors.subTextColor), width: 0.3)))
border: new Border.all(
color: Color(GSYColors.subTextColor), width: 0.3)))
.copyWith(
blockquoteDecoration: new BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(4.0)),
color: Color(GSYColors.subTextColor),
border: new Border.all(color: Color(GSYColors.subTextColor), width: 0.3)),
border: new Border.all(
color: Color(GSYColors.subTextColor), width: 0.3)),
blockquote: GSYConstant.smallTextWhite);
}

_getStyleSheetDark(BuildContext context) {
return _getCommonSheet(context, Color(GSYColors.primaryValue)).copyWith(
return _getCommonSheet(context, Color.fromRGBO(40, 44, 52, 1.00)).copyWith(
p: GSYConstant.smallTextWhite,
h1: GSYConstant.largeLargeTextWhite,
h2: GSYConstant.largeTextWhiteBold,
Expand All @@ -54,7 +58,7 @@ class GSYMarkdownWidget extends StatelessWidget {
}

_getStyleSheetWhite(BuildContext context) {
return _getCommonSheet(context, Color(GSYColors.primaryValue)).copyWith(
return _getCommonSheet(context, Color.fromRGBO(40, 44, 52, 1.00)).copyWith(
p: GSYConstant.smallText,
h1: GSYConstant.largeLargeText,
h2: GSYConstant.largeTextBold,
Expand All @@ -68,7 +72,7 @@ class GSYMarkdownWidget extends StatelessWidget {
}

_getStyleSheetTheme(BuildContext context) {
return _getCommonSheet(context, Color(GSYColors.subTextColor)).copyWith(
return _getCommonSheet(context, Color.fromRGBO(40, 44, 52, 1.00)).copyWith(
p: GSYConstant.smallTextWhite,
h1: GSYConstant.largeLargeTextWhite,
h2: GSYConstant.largeTextWhiteBold,
Expand Down Expand Up @@ -123,7 +127,9 @@ class GSYMarkdownWidget extends StatelessWidget {
String match = imageMatch.replaceAll("\)", "?raw=true)");
if (!match.contains(".svg") && match.contains("http")) {
///增加点击
String src = match.replaceAll(new RegExp(r'!\[.*\]\('), "").replaceAll(")", "");
String src = match
.replaceAll(new RegExp(r'!\[.*\]\('), "")
.replaceAll(")", "");
String actionMatch = "[$match]($src)";
match = actionMatch;
} else {
Expand All @@ -145,7 +151,9 @@ class GSYMarkdownWidget extends StatelessWidget {
for (Match srcMatch in srcTags) {
String srcString = srcMatch.group(0);
if (srcString != null && srcString.contains("http")) {
String newSrc = srcString.substring(srcString.indexOf("http"), srcString.length - 1) + "?raw=true";
String newSrc = srcString.substring(
srcString.indexOf("http"), srcString.length - 1) +
"?raw=true";

///增加点击
match = "[![]($newSrc)]($newSrc)";
Expand Down Expand Up @@ -181,9 +189,7 @@ class GSYMarkdownWidget extends StatelessWidget {
class GSYHighlighter extends SyntaxHighlighter {
@override
TextSpan format(String source) {
return new TextSpan(
text: source,
style: GSYConstant.smallTextWhite,
);
print(source);
return new DartSyntaxHighlighter().format(source);
}
}
Loading

0 comments on commit 4dad047

Please sign in to comment.