From 89c0837e8b7b29809b8d57f18e549cec2cd5a716 Mon Sep 17 00:00:00 2001 From: realth000 Date: Sun, 15 Sep 2024 07:13:26 +0800 Subject: [PATCH] fix(html): Fix missing italic style text --- CHANGELOG.md | 1 + lib/utils/html/html_muncher.dart | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7acc0eb6..2cbf5cba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - 网页:修复折叠卡片的尾部多余的空行。 - 网页:修复粗体字样式丢失的问题。 - 网页:修复某些情况下,嵌套的字体样式丢失的问题。 +- 网页:修复斜体字丢失的问题。 ### Changed diff --git a/lib/utils/html/html_muncher.dart b/lib/utils/html/html_muncher.dart index 60560b7c..e16a6c23 100644 --- a/lib/utils/html/html_muncher.dart +++ b/lib/utils/html/html_muncher.dart @@ -62,6 +62,9 @@ class _MunchState { /// Use bold font. bool bold = false; + /// Use italic font. + bool italic = false; + /// User underline. bool underline = false; @@ -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, ); @@ -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), @@ -912,6 +917,22 @@ final class _Muncher with LoggerMixin { return ret; } + List? _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 _buildHr(uh.Element element) { return [const WidgetSpan(child: Divider())]; }