Skip to content

Commit 8f3f0d6

Browse files
committed
content [nfc]: Pull out build methods for link, strong, emph
1 parent 93d5abf commit 8f3f0d6

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lib/widgets/content.dart

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,25 +333,20 @@ class _InlineContentBuilder {
333333
}
334334

335335
InlineSpan _buildNode(InlineContentNode node) {
336-
InlineSpan styled(List<InlineContentNode> nodes, TextStyle style) =>
337-
_buildNodes(nodes, style: style);
338-
339336
if (node is TextNode) {
340337
return TextSpan(text: node.text);
341338
} else if (node is LineBreakInlineNode) {
342339
// Each `<br/>` is followed by a newline, which browsers apparently ignore
343340
// and our parser doesn't. So don't do anything here.
344341
return const TextSpan(text: "");
345342
} else if (node is StrongNode) {
346-
return styled(node.nodes, const TextStyle(fontWeight: FontWeight.w600));
343+
return _buildStrong(node);
347344
} else if (node is EmphasisNode) {
348-
return styled(node.nodes, const TextStyle(fontStyle: FontStyle.italic));
345+
return _buildEmphasis(node);
346+
} else if (node is LinkNode) {
347+
return _buildLink(node);
349348
} else if (node is InlineCodeNode) {
350349
return _buildInlineCode(node);
351-
} else if (node is LinkNode) {
352-
// TODO make link touchable
353-
return styled(node.nodes,
354-
TextStyle(color: const HSLColor.fromAHSL(1, 200, 1, 0.4).toColor()));
355350
} else if (node is UserMentionNode) {
356351
return WidgetSpan(alignment: PlaceholderAlignment.middle,
357352
child: UserMention(node: node));
@@ -369,6 +364,18 @@ class _InlineContentBuilder {
369364
}
370365
}
371366

367+
InlineSpan _buildStrong(StrongNode node) => _buildNodes(node.nodes,
368+
style: const TextStyle(fontWeight: FontWeight.w600));
369+
370+
InlineSpan _buildEmphasis(EmphasisNode node) => _buildNodes(node.nodes,
371+
style: const TextStyle(fontStyle: FontStyle.italic));
372+
373+
InlineSpan _buildLink(LinkNode node) {
374+
// TODO make link touchable
375+
return _buildNodes(node.nodes,
376+
style: TextStyle(color: const HSLColor.fromAHSL(1, 200, 1, 0.4).toColor()));
377+
}
378+
372379
InlineSpan _buildInlineCode(InlineCodeNode node) {
373380
// TODO `code` elements: border, padding -- seems hard
374381
//

0 commit comments

Comments
 (0)