mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-01 20:43:20 +08:00
BackLinks: Render the [[term]] in bold
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:gitjournal/core/link.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
import 'package:gitjournal/folder_views/common.dart';
|
import 'package:gitjournal/folder_views/common.dart';
|
||||||
@ -117,6 +118,8 @@ class NoteSnippet extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
assert(note != null);
|
||||||
|
|
||||||
var theme = Theme.of(context);
|
var theme = Theme.of(context);
|
||||||
var textTheme = theme.textTheme;
|
var textTheme = theme.textTheme;
|
||||||
var title = note.title;
|
var title = note.title;
|
||||||
@ -169,12 +172,44 @@ class NoteSnippet extends StatelessWidget {
|
|||||||
(line) => line.contains('[${link.term}]'),
|
(line) => line.contains('[${link.term}]'),
|
||||||
orElse: () => "",
|
orElse: () => "",
|
||||||
);
|
);
|
||||||
// vHanda: This isn't a very fool proof way of figuring out the line
|
|
||||||
|
|
||||||
return Text(
|
// vHanda: This isn't a very fool proof way of figuring out the line
|
||||||
paragraph,
|
// FIXME: Ideally, we should be parsing the entire markdown properly and rendering all of it
|
||||||
style: textTheme.bodyText2,
|
return RichText(
|
||||||
|
text: TextSpan(children: _extraMetaLinks(textTheme.bodyText2, paragraph)),
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<TextSpan> _extraMetaLinks(TextStyle textStyle, String line) {
|
||||||
|
var regExp = MetaLinkSyntax().pattern;
|
||||||
|
|
||||||
|
var spans = <TextSpan>[];
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
var match = regExp.firstMatch(line);
|
||||||
|
if (match == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var text = line.substring(0, match.start);
|
||||||
|
spans.add(TextSpan(style: textStyle, text: text));
|
||||||
|
|
||||||
|
text = match.group(0);
|
||||||
|
spans.add(TextSpan(
|
||||||
|
style: textStyle.copyWith(fontWeight: FontWeight.bold), text: text));
|
||||||
|
|
||||||
|
if (match.end < line.length) {
|
||||||
|
line = line.substring(match.end);
|
||||||
|
} else {
|
||||||
|
line = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.isNotEmpty) {
|
||||||
|
spans.add(TextSpan(style: textStyle, text: line));
|
||||||
|
}
|
||||||
|
|
||||||
|
return spans;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user