Skip to content

Commit 3ec6471

Browse files
committed
add fixes and version bump
1 parent 8524888 commit 3ec6471

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.3.1] - 8th Aug 2021
2+
- Fix link colour in inline code blocks
3+
- Fix long code blocks causing language autodetection to take long
4+
15
## [0.3.0] - 11th Apr 2021
26
- Update matrix: URI schemes
37
- Fix small rendering bug with flutter 2

lib/code_block.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ class _CodeBlockState extends State<CodeBlock> {
4141
void initState() {
4242
super.initState();
4343
if (widget.language == null) {
44-
final hashKey = sha1.convert(utf8.encode(widget.code)).toString();
44+
// the first 250 chars should be enough to detect the code language, hopefully
45+
final codeFragment = widget.code.length > 250
46+
? widget.code.substring(0, 250)
47+
: widget.code;
48+
final hashKey = sha1.convert(utf8.encode(codeFragment)).toString();
4549
if (_detectionMap[hashKey] != null) {
4650
language = _detectionMap[hashKey];
4751
} else {
@@ -52,7 +56,7 @@ class _CodeBlockState extends State<CodeBlock> {
5256
return lang;
5357
}
5458
}
55-
return _autodetectLanguage(widget.code);
59+
return _autodetectLanguage(codeFragment);
5660
}();
5761
_futureDetectionMap[hashKey].then((String lang) async {
5862
_detectionMap[hashKey] = lang;
@@ -94,16 +98,16 @@ class _CodeBlockState extends State<CodeBlock> {
9498
BoxConstraints(maxHeight: widget.maxLines == 1 ? 20 : 250),
9599
child: Scrollbar(
96100
isAlwaysShown: true,
97-
controller: _horizontalScrollController,
101+
controller: _verticalScrollController,
98102
child: SingleChildScrollView(
99-
scrollDirection: Axis.horizontal,
100-
controller: _horizontalScrollController,
103+
scrollDirection: Axis.vertical,
104+
controller: _verticalScrollController,
101105
child: Scrollbar(
102106
isAlwaysShown: true,
103-
controller: _verticalScrollController,
107+
controller: _horizontalScrollController,
104108
child: SingleChildScrollView(
105-
scrollDirection: Axis.vertical,
106-
controller: _verticalScrollController,
109+
scrollDirection: Axis.horizontal,
110+
controller: _horizontalScrollController,
107111
child: HighlightView(
108112
widget.code.replaceAll(RegExp(r'\n$'), ''),
109113
language: language,

lib/rich_text_parser.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ class HtmlRichTextParser extends StatelessWidget {
728728
));
729729
nextContext.linkStyle = parseContext.linkStyle.merge(TextStyle(
730730
fontFamily: 'monospace',
731+
color: monokaiTheme['root'].color,
731732
backgroundColor: monokaiTheme['root'].backgroundColor,
732733
));
733734
break;
@@ -894,9 +895,8 @@ class HtmlRichTextParser extends StatelessWidget {
894895
RegExp(r"^[@#!+][^:]+:[^\/]+$").firstMatch(identifier) !=
895896
null;
896897
} else {
897-
final match =
898-
RegExp(r"^matrix:(r|roomid|u)\/([^\/]+)$")
899-
.firstMatch(urlLower.split('?').first.split('#').first);
898+
final match = RegExp(r"^matrix:(r|roomid|u)\/([^\/]+)$")
899+
.firstMatch(urlLower.split('?').first.split('#').first);
900900
isPill = match != null;
901901
if (isPill) {
902902
identifier = {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_matrix_html
22
description: A Flutter widget for rendering static matrix html tags as Flutter widgets. (Will render over 70 different html tags!)
3-
version: 0.3.0
3+
version: 0.3.1
44
homepage: https://github.com/Sorunome/flutter_matrix_html
55

66
environment:

0 commit comments

Comments
 (0)