Skip to content

Commit

Permalink
fix(html): Fix missing italic style text
Browse files Browse the repository at this point in the history
  • Loading branch information
realth000 committed Sep 14, 2024
1 parent 7193059 commit 89c0837
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- 网页:修复折叠卡片的尾部多余的空行。
- 网页:修复粗体字样式丢失的问题。
- 网页:修复某些情况下,嵌套的字体样式丢失的问题。
- 网页:修复斜体字丢失的问题。

### Changed

Expand Down
21 changes: 21 additions & 0 deletions lib/utils/html/html_muncher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class _MunchState {
/// Use bold font.
bool bold = false;

/// Use italic font.
bool italic = false;

/// User underline.
bool underline = false;

Expand Down Expand Up @@ -244,6 +247,7 @@ final class _Muncher with LoggerMixin {
if (state.underline) TextDecoration.underline,
if (state.lineThrough) TextDecoration.lineThrough,
]),
fontStyle: state.italic ? FontStyle.italic : null,
decorationThickness: 1.5,
);

Expand Down Expand Up @@ -303,6 +307,7 @@ final class _Muncher with LoggerMixin {
'code' => _buildCode(node),
'dl' => _buildDl(node),
'b' => _buildB(node),
'i' => _buildI(node),
'hr' => _buildHr(node),
'pre' => _buildPre(node),
'details' => _buildDetails(node),
Expand Down Expand Up @@ -912,6 +917,22 @@ final class _Muncher with LoggerMixin {
return ret;
}
List<InlineSpan>? _buildI(uh.Element element) {
// Ignore thread last modified info element.
// This kind of node is specially handled.
if (element.classes.contains('pstatus')) {
return null;
}
final origItalic = state.italic;
state.italic = true;
final ret = _munch(element);
state.italic = origItalic;
if (ret == null) {
return null;
}
return ret;
}
List<InlineSpan> _buildHr(uh.Element element) {
return [const WidgetSpan(child: Divider())];
}
Expand Down

0 comments on commit 89c0837

Please sign in to comment.