Skip to content

Commit f51a0ac

Browse files
committed
перенос пакета подсветки в проект
- код теперь выделяемый - удалены неиспользуемые темы
1 parent 0e42437 commit f51a0ac

File tree

13 files changed

+621
-7
lines changed

13 files changed

+621
-7
lines changed

lib/presentation/widget/html_view_widget.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
55
import 'package:flutter_bloc/flutter_bloc.dart';
66
import 'package:flutter_highlight/flutter_highlight.dart';
77
import 'package:flutter_highlight/themes/darcula.dart';
8+
import 'package:flutter_highlight/themes/github_gist.dart';
89
import 'package:flutter_svg/flutter_svg.dart';
910
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
1011
import 'package:fwfh_svg/fwfh_svg.dart';
@@ -362,7 +363,11 @@ abstract class CustomBuildOp {
362363
);
363364
final padding = const EdgeInsets.all(12);
364365

365-
final codeTheme = darculaTheme;
366+
final codeTheme = switch (context.theme.brightness) {
367+
Brightness.dark => darculaTheme,
368+
Brightness.light => githubGistTheme,
369+
};
370+
366371
final bgColor =
367372
codeTheme['root']?.backgroundColor ??
368373
context.theme.colors.cardHighlight;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 20e59316b8b8474554b38493b8ca888794b0234a
8+
channel: stable
9+
10+
project_type: package
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# [0.7.0](https://github.com/git-touch/highlight/compare/v0.6.0...v.7.0) (2021-03-07)
2+
3+
### Features
4+
5+
- null safety ([696206a](https://github.com/git-touch/highlight/commit/696206ad53dac56d5653622617ba6fda7c857c1a))
6+
7+
# [0.6.0](https://github.com/git-touch/highlight/compare/v0.5.0...v0.6.0) (2020-02-04)
8+
9+
### Bug Fixes
10+
11+
- pedantic lints ([37b4469](https://github.com/git-touch/highlight/commit/37b4469c90d775ab559b12da20596e2f2d87a6fb))
12+
13+
# [0.5.0](https://github.com/git-touch/highlight/compare/v0.4.1...v0.5.0) (2019-11-14)
14+
15+
### Bug Fixes
16+
17+
- richtext ([036f5a9](https://github.com/git-touch/highlight/commit/036f5a98e395b10a8c3c7cd7821a4044cc96ff6c))
18+
19+
### Features
20+
21+
- add gn and solidity ([196c1c4](https://github.com/git-touch/highlight/commit/196c1c4a11da5619c3c90171cd501043daac30fd))
22+
23+
## [0.4.1](https://github.com/git-touch/highlight/compare/v0.4.0...v0.4.1) (2019-11-12)
24+
25+
### Bug Fixes
26+
27+
- update path ([9cfeb1a](https://github.com/git-touch/highlight/commit/9cfeb1a77c83794e8726b3e03eb3620634f97970))
28+
29+
### Features
30+
31+
- add graphql and vue ([5f558bf](https://github.com/git-touch/highlight/commit/5f558bfd6511a1a84d2b9f0949bb0282a3139e07))
32+
- add highlight core module for more control ([c2bee79](https://github.com/git-touch/highlight/commit/c2bee79b1707c85e7a36f8dbc0dcfa3bdfdfca88))
33+
34+
# [0.4.0](https://github.com/git-touch/highlight/compare/v0.3.0...v0.4.0) (2019-09-20)
35+
36+
### Bug Fixes
37+
38+
- use plaintext mode if no language match ([3c8bb95](https://github.com/git-touch/highlight/commit/3c8bb95f28e8248f2b156b6343ba7f2c4a6c8243))
39+
- **gallery:** correct language ([77855a0](https://github.com/git-touch/highlight/commit/77855a027ca206a615ef09c8314c21bc4163d219))
40+
- drop dart:io dependency for web ([3aa0155](https://github.com/git-touch/highlight/commit/3aa0155d2d04946682a95bd55b421a697171bab1))
41+
42+
### Features
43+
44+
- auto detection param ([de22fa4](https://github.com/git-touch/highlight/commit/de22fa41090283bc4d2ec56ca934cb29bd09f236))
45+
46+
# [0.3.0](https://github.com/git-touch/highlight/compare/v0.2.0...v0.3.0) (2019-09-02)
47+
48+
### Bug Fixes
49+
50+
- background color with image ([0a2d780](https://github.com/git-touch/highlight/commit/0a2d7802a7bd449a853195977e09dbd92143b36a))
51+
- example map gen ([f3f6bdd](https://github.com/git-touch/highlight/commit/f3f6bddb23e3024bf3a6dc6883287e56bba250ac))
52+
- remove deprecated theme ([2e492b6](https://github.com/git-touch/highlight/commit/2e492b6eb18290482c58ce1f5d2ca9068f212e49))
53+
54+
### Features
55+
56+
- **gallery:** add source code link ([3bbc1c1](https://github.com/git-touch/highlight/commit/3bbc1c15d5b1398e05463cc36e6fb7827f514198))
57+
58+
# [0.2.0](https://github.com/git-touch/highlight/compare/v0.1.0...v0.2.0) (2019-08-26)
59+
60+
### Bug Fixes
61+
62+
- drop dart:io dependency at platform web ([05963ef](https://github.com/git-touch/highlight/commit/05963ef3aaf6a6ced1f295765dce207750f0be65))
63+
- rename folder following pub ([510d607](https://github.com/git-touch/highlight/commit/510d6073abdc7cf05e73040ce85eb4dc1124f42c))
64+
65+
### Features
66+
67+
- add padding and textStyle props ([d4ed23d](https://github.com/git-touch/highlight/commit/d4ed23d01248e9e477087c9bc91b2a3ad3ab96c0))
68+
69+
# [0.1.0](https://github.com/git-touch/highlight/compare/2ca2e95262741d908de1b2ae769770de1f80756c...v0.1.0) (2019-08-25)
70+
71+
### Bug Fixes
72+
73+
- alias register ([bfc594e](https://github.com/git-touch/highlight/commit/bfc594ea3dc8a6272fb9ad25f93596975b13e9c6))
74+
- catch int parse error ([41aac3d](https://github.com/git-touch/highlight/commit/41aac3d007d1598456d0becd99743b88da3e1b79))
75+
- className empty ([b16005e](https://github.com/git-touch/highlight/commit/b16005ea72022f929501b8e441e5128151a5df2c))
76+
- dropdown menu style ([9bcd55c](https://github.com/git-touch/highlight/commit/9bcd55ca1e7782e7166b2e90a772a334664baf33))
77+
- find same mode instances for reusing ([a0bffd5](https://github.com/git-touch/highlight/commit/a0bffd5254c793acf3bcd0b170d837c0e2b31cec))
78+
- flutter highlight traverse ([6ae2549](https://github.com/git-touch/highlight/commit/6ae2549a7f1c929069a96208aed74b07d08c17cd))
79+
- join regexp ([28a4e32](https://github.com/git-touch/highlight/commit/28a4e32c004f84e8c60ce2780d032356ac827e38))
80+
- keyword match reference language ([4ec6476](https://github.com/git-touch/highlight/commit/4ec647655f2b4321845c1f51cbcf18e2ed1fea24))
81+
- languages alias ([1a88ff6](https://github.com/git-touch/highlight/commit/1a88ff601c24c824503c4f77b24e159eb534ed89))
82+
- match sub language ([7b0e509](https://github.com/git-touch/highlight/commit/7b0e509046b2f9d6487373de518c0db274bd6307))
83+
- merge styles of same selector ([b678d03](https://github.com/git-touch/highlight/commit/b678d03fffa4666ab37909aaeabc290675777409))
84+
- normalize types ([74cd977](https://github.com/git-touch/highlight/commit/74cd9770c96ccce50d1e7d3082675dfff80a057b))
85+
- regexp with multiline flag ([e9f2a81](https://github.com/git-touch/highlight/commit/e9f2a81f50017b45f9f30e956642a51e3b0fedd4))
86+
- stack overflow, update test cases ([1117023](https://github.com/git-touch/highlight/commit/1117023db772bafd8de084f141b6c1b60a9dd3d9))
87+
- sub language field type ([24c8dc1](https://github.com/git-touch/highlight/commit/24c8dc11d89cc14f1583dbbf9f03f26516804af0))
88+
- terminators filter ([2bdfc37](https://github.com/git-touch/highlight/commit/2bdfc374b7c9bdbf2f41bef5c23e7b2a1c5552f8))
89+
- trim result before comparing ([f7d9680](https://github.com/git-touch/highlight/commit/f7d968010491b07b3297442fd6ae7a1fd9927e3c))
90+
- try to circular object ([9099402](https://github.com/git-touch/highlight/commit/909940208eb1207bb032414f74bcf4c15959fcc8))
91+
92+
### Features
93+
94+
- **gallery:** add ga ([8e5b8c0](https://github.com/git-touch/highlight/commit/8e5b8c0ac0027aa3e1439cacebdf6a3288804efe))
95+
- default style ([2d1e72f](https://github.com/git-touch/highlight/commit/2d1e72f2d4f88c34c4dc56302b4d101e70a6257c))
96+
- use default theme ([505aa11](https://github.com/git-touch/highlight/commit/505aa113051bb674dced4300600e1af5d1f146b1))
97+
- **gallery:** add language select ([acb429c](https://github.com/git-touch/highlight/commit/acb429c31f3c3b751b847e2b2a66541d10d829fa))
98+
- add container background color ([7edd5aa](https://github.com/git-touch/highlight/commit/7edd5aab0bdbebafd2172c8dc234f8feddf37258))
99+
- add generated style files ([4da9ce8](https://github.com/git-touch/highlight/commit/4da9ce867691ac95bc924d08dc09a74b76baec48))
100+
- add highlighter widget ([6f8b529](https://github.com/git-touch/highlight/commit/6f8b5299366015d9a7ae28d00f26342df31584db))
101+
- add refs to fix circular issue ([4470f4a](https://github.com/git-touch/highlight/commit/4470f4a0bf59b46d64b86bc07840b2062a458e0a))
102+
- add tools ([2ca2e95](https://github.com/git-touch/highlight/commit/2ca2e95262741d908de1b2ae769770de1f80756c))
103+
- change exposed api ([11b8c9c](https://github.com/git-touch/highlight/commit/11b8c9cd1e3d9bb1848d6e3fb9d15dc70d945840))
104+
- compile mode ([2811fbb](https://github.com/git-touch/highlight/commit/2811fbb1814995bc15c48710b6ed0bea2b198767))
105+
- copy flutter_highlight to gallery, with flutter_web replacement ([4ea17fc](https://github.com/git-touch/highlight/commit/4ea17fc3683ce7bfcff3f43068e8a4b3b69aa3f0))
106+
- core highlight ([3f8ca78](https://github.com/git-touch/highlight/commit/3f8ca78ea2cf6c58bde4ead2cbfdc9a1485e1bd4))
107+
- json generator ([c5f9e47](https://github.com/git-touch/highlight/commit/c5f9e47ed186cf720e198974d6f40cc9e829b69d))
108+
- output tree node instead of html string ([64376d7](https://github.com/git-touch/highlight/commit/64376d7e6df73b4492318292123efe18ab80cc4b))
109+
- register all languages by default ([33299d3](https://github.com/git-touch/highlight/commit/33299d3cb4d37569e061039a648e2e96eeb1e049))
110+
- select highlight theme at gallery ([063c06c](https://github.com/git-touch/highlight/commit/063c06ce74e7cf142a26cc45df744c9cf0b43938))
111+
- support sub languages ([a4c419b](https://github.com/git-touch/highlight/commit/a4c419b2689e4c0e15e630c6cb8007ee7ac8f35a))
112+
- use es modules ([63778cb](https://github.com/git-touch/highlight/commit/63778cbaa3881b0adbed49d9002193c14b7e30e6))

packages/flutter_highlight/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Rongjian Zhang
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# flutter_highlight
2+
3+
[![pub](https://img.shields.io/pub/v/flutter_highlight)](https://pub.dev/packages/flutter_highlight)
4+
5+
Syntax highlighter for Flutter. https://git-touch.github.io/highlight/
6+
7+
## Usage
8+
9+
```dart
10+
import 'package:flutter/material.dart';
11+
import 'package:flutter_highlight/flutter_highlight.dart';
12+
import 'package:flutter_highlight/themes/github.dart';
13+
14+
class MyWidget extends StatelessWidget {
15+
@override
16+
Widget build(BuildContext context) {
17+
var code = '''main() {
18+
print("Hello, World!");
19+
}
20+
''';
21+
22+
return HighlightView(
23+
// The original code to be highlighted
24+
code,
25+
26+
// Specify language
27+
// It is recommended to give it a value for performance
28+
language: 'dart',
29+
30+
// Specify highlight theme
31+
// All available themes are listed in `themes` folder
32+
theme: githubTheme,
33+
34+
// Specify padding
35+
padding: EdgeInsets.all(12),
36+
37+
// Specify text style
38+
textStyle: TextStyle(
39+
fontFamily: 'My awesome monospace font',
40+
fontSize: 16,
41+
),
42+
);
43+
}
44+
}
45+
```
46+
47+
## References
48+
49+
- [All available languages](https://github.com/pd4d10/highlight/tree/master/highlight/lib/languages)
50+
- [All available themes](https://github.com/pd4d10/highlight/blob/master/flutter_highlight/lib/themes)
51+
52+
## License
53+
54+
MIT
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// ignore_for_file: no_leading_underscores_for_local_identifiers
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:highlight/highlight.dart' show highlight, Node;
5+
6+
/// Highlight Flutter Widget
7+
class HighlightView extends StatelessWidget {
8+
/// The original code to be highlighted
9+
final String source;
10+
11+
/// Highlight language
12+
///
13+
/// It is recommended to give it a value for performance
14+
///
15+
/// [All available languages](https://github.com/pd4d10/highlight/tree/master/highlight/lib/languages)
16+
final String? language;
17+
18+
/// Highlight theme
19+
///
20+
/// [All available themes](https://github.com/pd4d10/highlight/blob/master/flutter_highlight/lib/themes)
21+
final Map<String, TextStyle> theme;
22+
23+
/// Padding
24+
final EdgeInsetsGeometry padding;
25+
26+
/// Text styles
27+
///
28+
/// Specify text styles such as font family and font size
29+
final TextStyle? textStyle;
30+
31+
HighlightView(
32+
String input, {
33+
Key? key,
34+
this.language,
35+
this.theme = const {},
36+
this.padding = EdgeInsets.zero,
37+
this.textStyle,
38+
int tabSize = 8, // https://github.com/flutter/flutter/issues/50087
39+
}) : source = input.replaceAll('\t', ' ' * tabSize),
40+
super(key: key);
41+
42+
List<TextSpan> _convert(List<Node> nodes) {
43+
List<TextSpan> spans = [];
44+
var currentSpans = spans;
45+
List<List<TextSpan>> stack = [];
46+
47+
void _traverse(Node node) {
48+
if (node.value != null) {
49+
currentSpans.add(node.className == null
50+
? TextSpan(text: node.value)
51+
: TextSpan(text: node.value, style: theme[node.className!]));
52+
} else if (node.children != null) {
53+
List<TextSpan> tmp = [];
54+
currentSpans
55+
.add(TextSpan(children: tmp, style: theme[node.className!]));
56+
stack.add(currentSpans);
57+
currentSpans = tmp;
58+
59+
for (var n in node.children!) {
60+
_traverse(n);
61+
if (n == node.children!.last) {
62+
currentSpans = stack.isEmpty ? spans : stack.removeLast();
63+
}
64+
}
65+
}
66+
}
67+
68+
for (var node in nodes) {
69+
_traverse(node);
70+
}
71+
72+
return spans;
73+
}
74+
75+
static const _rootKey = 'root';
76+
static const _defaultFontColor = Color(0xff000000);
77+
static const _defaultBackgroundColor = Color(0xffffffff);
78+
79+
// dart:io is not available at web platform currently
80+
// See: https://github.com/flutter/flutter/issues/39998
81+
// So we just use monospace here for now
82+
static const _defaultFontFamily = 'monospace';
83+
84+
@override
85+
Widget build(BuildContext context) {
86+
var _textStyle = TextStyle(
87+
fontFamily: _defaultFontFamily,
88+
color: theme[_rootKey]?.color ?? _defaultFontColor,
89+
);
90+
if (textStyle != null) {
91+
_textStyle = _textStyle.merge(textStyle);
92+
}
93+
94+
return DecoratedBox(
95+
decoration: BoxDecoration(
96+
color: theme[_rootKey]?.backgroundColor ?? _defaultBackgroundColor,
97+
),
98+
child: Padding(
99+
padding: padding,
100+
child: SelectableText.rich(
101+
TextSpan(
102+
style: _textStyle,
103+
children:
104+
_convert(highlight.parse(source, language: language).nodes!),
105+
),
106+
),
107+
),
108+
);
109+
}
110+
}

packages/flutter_highlight/lib/theme_map.dart

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/flutter_highlight/lib/themes/darcula.dart

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)