Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add syntax highlight #13

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ const kWelcomeButtonText = 'See our projects';

const kBaseColor = Colors.grey;
const kHighlightColor = Colors.white;

const kYaruTutorialMarkDown =
'https://raw.githubusercontent.com/ubuntu-flutter-community/yaru_tutorial/master/README.md';
23 changes: 20 additions & 3 deletions lib/getting_started_page.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:http/http.dart' as http;
import 'package:markdown_syntax_highlighter/markdown_syntax_highlighter.dart';
import 'package:yaru_widgets/constants.dart';
import 'package:yaru_widgets/widgets.dart';

import 'build_context_x.dart';
import 'constants.dart';
import 'sub_page.dart';

class GettingStartedPage extends StatelessWidget {
Expand All @@ -27,9 +29,11 @@ class GettingStartedPage extends StatelessWidget {
return Markdown(
padding: EdgeInsets.symmetric(
vertical: kYaruPagePadding,
horizontal: width < 700 ? kYaruPagePadding : width * 0.2,
horizontal: width < 700 ? kYaruPagePadding : width * 0.18,
),
data: shot.data!,
selectable: true,
syntaxHighlighter: DartSH(),
);
},
),
Expand All @@ -38,9 +42,22 @@ class GettingStartedPage extends StatelessWidget {
}
}

class DartSH extends SyntaxHighlighter {
@override
TextSpan format(String source) {
final SyntaxHighlighterStyle style =
SyntaxHighlighterStyle.darkThemeStyle();
return TextSpan(
style: const TextStyle(fontFamily: 'monospace', fontSize: 10.0),
children: <TextSpan>[
DartSyntaxHighlighter(style).format(source),
],
);
}
}

Future<String> loadMarkdown() async {
const address =
'https://raw.githubusercontent.com/ubuntu-flutter-community/yaru_tutorial/master/README.md';
const address = kYaruTutorialMarkDown;
final uri = Uri.parse(address);

final response = await http.get(uri);
Expand Down
24 changes: 24 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_highlighter:
dependency: "direct main"
description:
name: flutter_highlighter
sha256: "93173afd47a9ada53f3176371755e7ea4a1065362763976d06d6adfb4d946e10"
url: "https://pub.dev"
source: hosted
version: "0.1.1"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -144,6 +152,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
highlighter:
dependency: transitive
description:
name: highlighter
sha256: "92180c72b9da8758e1acf39a45aa305a97dcfe2fdc8f3d1d2947c23f2772bfbc"
url: "https://pub.dev"
source: hosted
version: "0.1.1"
html:
dependency: transitive
description:
Expand Down Expand Up @@ -192,6 +208,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.2.1"
markdown_syntax_highlighter:
dependency: "direct main"
description:
name: markdown_syntax_highlighter
sha256: "517308d81b0c13921a91da3aa78d4b7efea7200387239a00bd214ee80e6723c8"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
matcher:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ dependencies:
flutter:
sdk: flutter

flutter_highlighter: ^0.1.1
flutter_markdown: ^0.6.20
flutter_tabler_icons: ^1.21.0
github: ^9.23.0
http: ^1.2.0
markdown_syntax_highlighter: ^1.1.0
path: ^1.8.3
shimmer: ^3.0.0
ubuntu_service: ^0.3.1
Expand Down