Skip to content

Commit 727b1a3

Browse files
committed
handle links in code blocks correctly
1 parent d31dcf5 commit 727b1a3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## ???
22
- Fix assuming css color names are lowercase
33
- Fix too much whitespace between table and tr tags causing issues
4+
- Properly handle links inside of `<code>` blocks
45

56
## [0.1.13] - 20th Nov 2020:
67
- Switch latex rendering to flutter_math

lib/rich_text_parser.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ class ParseContext {
275275
bool spansOnly = false;
276276
bool inBlock = false;
277277
TextStyle childStyle;
278+
TextStyle linkStyle;
278279
bool shrinkToFit;
279280
int maxLines;
280281
double indentPadding = 0;
@@ -292,6 +293,7 @@ class ParseContext {
292293
this.spansOnly = false,
293294
this.inBlock = false,
294295
this.childStyle,
296+
this.linkStyle,
295297
this.shrinkToFit,
296298
this.maxLines,
297299
this.indentPadding = 0,
@@ -312,6 +314,7 @@ class ParseContext {
312314
spansOnly = parseContext.spansOnly;
313315
inBlock = parseContext.inBlock;
314316
childStyle = parseContext.childStyle ?? TextStyle();
317+
linkStyle = parseContext.linkStyle ?? TextStyle();
315318
shrinkToFit = parseContext.shrinkToFit;
316319
maxLines = parseContext.maxLines;
317320
indentPadding = parseContext.indentPadding;
@@ -550,6 +553,7 @@ class HtmlRichTextParser extends StatelessWidget {
550553
ParseContext parseContext = ParseContext(
551554
rootWidgetList: widgetList,
552555
childStyle: DefaultTextStyle.of(context).style,
556+
linkStyle: linkStyle ?? TextStyle(),
553557
shrinkToFit: shrinkToFit,
554558
maxLines: maxLines,
555559
indentSize: indentSize,
@@ -647,7 +651,7 @@ class HtmlRichTextParser extends StatelessWidget {
647651
themeData: Theme.of(buildContext),
648652
onLinkTap: onLinkTap,
649653
textStyle: parseContext.childStyle,
650-
linkStyle: parseContext.childStyle.merge(linkStyle),
654+
linkStyle: parseContext.childStyle.merge(parseContext.linkStyle),
651655
);
652656

653657
// in this class, a ParentElement must be a BlockText, LinkTextSpan, Row, Column, TextSpan
@@ -716,6 +720,10 @@ class HtmlRichTextParser extends StatelessWidget {
716720
backgroundColor: monokaiTheme['root'].backgroundColor,
717721
color: monokaiTheme['root'].color,
718722
));
723+
nextContext.linkStyle = parseContext.linkStyle.merge(TextStyle(
724+
fontFamily: 'monospace',
725+
backgroundColor: monokaiTheme['root'].backgroundColor,
726+
));
719727
break;
720728
case "ins":
721729
case "u":

0 commit comments

Comments
 (0)