fix blockquote inline styling (#334)

This commit is contained in:
Tim Bierbaum
2021-02-10 02:04:27 +00:00
committed by GitHub
parent 699d3b6784
commit e6b12d6e9d
2 changed files with 79 additions and 1 deletions

View File

@ -296,7 +296,7 @@ class MarkdownBuilder implements md.NodeVisitor {
child = _buildRichText(
TextSpan(
style: _isInBlockquote
? _inlines.last.style!.merge(styleSheet.blockquote)
? styleSheet.blockquote!.merge(_inlines.last.style)
: _inlines.last.style,
text: _isInBlockquote ? text.text : trimText(text.text),
recognizer: _linkHandlers.isNotEmpty ? _linkHandlers.last : null,

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_test/flutter_test.dart';
@ -24,5 +25,82 @@ void defineTests() {
expectTextStrings(widgets, <String>['quote']);
},
);
testWidgets(
'should work with styling',
(WidgetTester tester) async {
final ThemeData theme = ThemeData.light().copyWith(
textTheme: textTheme,
);
final MarkdownStyleSheet styleSheet = MarkdownStyleSheet.fromTheme(
theme,
);
const String data =
'> this is a link: [Markdown guide](https://www.markdownguide.org) and this is **bold** and *italic*';
await tester.pumpWidget(
boilerplate(
MarkdownBody(
data: data,
styleSheet: styleSheet,
),
),
);
final Iterable<Widget> widgets = tester.allWidgets;
final DecoratedBox blockQuoteContainer = tester.widget(
find.byType(DecoratedBox),
);
final RichText qouteText = tester.widget(find.byType(RichText));
final List<TextSpan> styledTextParts =
(qouteText.text as TextSpan).children!.cast<TextSpan>();
expectTextStrings(
widgets,
['this is a link: Markdown guide and this is bold and italic'],
);
expect(
(blockQuoteContainer.decoration as BoxDecoration).color,
(styleSheet.blockquoteDecoration as BoxDecoration).color,
);
expect(
(blockQuoteContainer.decoration as BoxDecoration).borderRadius,
(styleSheet.blockquoteDecoration as BoxDecoration).borderRadius,
);
/// this is a link
expect(styledTextParts[0].text, 'this is a link: ');
expect(
styledTextParts[0].style!.color,
theme.textTheme.bodyText2!.color,
);
/// Markdown guide
expect(styledTextParts[1].text, 'Markdown guide');
expect(styledTextParts[1].style!.color, Colors.blue);
/// and this is
expect(styledTextParts[2].text, ' and this is ');
expect(
styledTextParts[2].style!.color,
theme.textTheme.bodyText2!.color,
);
/// bold
expect(styledTextParts[3].text, 'bold');
expect(styledTextParts[3].style!.fontWeight, FontWeight.bold);
/// and
expect(styledTextParts[4].text, ' and ');
expect(
styledTextParts[4].style!.color,
theme.textTheme.bodyText2!.color,
);
/// italic
expect(styledTextParts[5].text, 'italic');
expect(styledTextParts[5].style!.fontStyle, FontStyle.italic);
},
);
});
}