Skip to content

Conversation

@Johnson-zs
Copy link
Contributor

  1. Implement new markdown preview plugin with text/markdown MIME type support
  2. Add MarkdownBrowser widget using QTextBrowser with markdown rendering capabilities
  3. Create preview context widget with proper layout and styling
  4. Implement file reading with 5MB size limit and UTF-8 encoding support
  5. Add plugin detection mechanism to prevent text/* from intercepting text/markdown files
  6. Support relative image paths resolution using base directory

Log: Added markdown file preview functionality

Influence:

  1. Test preview of various markdown files with different sizes and encodings
  2. Verify markdown rendering including headers, lists, links, and code blocks
  3. Test relative image paths resolution in markdown files
  4. Verify plugin priority when both text/markdown and text/* plugins exist
  5. Test file size limits with files larger than 5MB
  6. Check preview switching between different file types
  7. Verify external link handling in markdown content

feat: 添加 Markdown 文件预览插件

  1. 实现新的 Markdown 预览插件,支持 text/markdown MIME 类型
  2. 添加使用 QTextBrowser 的 MarkdownBrowser 控件,支持 Markdown 渲染
  3. 创建预览上下文控件,包含适当的布局和样式
  4. 实现文件读取功能,支持 5MB 大小限制和 UTF-8 编码
  5. 添加插件检测机制,防止 text/* 插件拦截 text/markdown 文件
  6. 支持使用基础目录解析相对图片路径

Log: 新增 Markdown 文件预览功能

Influence:

  1. 测试不同大小和编码的 Markdown 文件预览
  2. 验证 Markdown 渲染效果,包括标题、列表、链接和代码块
  3. 测试 Markdown 文件中相对图片路径的解析
  4. 验证当 text/markdown 和 text/* 插件同时存在时的优先级
  5. 测试超过 5MB 文件的尺寸限制处理
  6. 检查不同文件类型之间的预览切换
  7. 验证 Markdown 内容中外部链接的处理

1. Implement new markdown preview plugin with text/markdown MIME type
support
2. Add MarkdownBrowser widget using QTextBrowser with markdown rendering
capabilities
3. Create preview context widget with proper layout and styling
4. Implement file reading with 5MB size limit and UTF-8 encoding support
5. Add plugin detection mechanism to prevent text/* from intercepting
text/markdown files
6. Support relative image paths resolution using base directory

Log: Added markdown file preview functionality

Influence:
1. Test preview of various markdown files with different sizes and
encodings
2. Verify markdown rendering including headers, lists, links, and code
blocks
3. Test relative image paths resolution in markdown files
4. Verify plugin priority when both text/markdown and text/* plugins
exist
5. Test file size limits with files larger than 5MB
6. Check preview switching between different file types
7. Verify external link handling in markdown content

feat: 添加 Markdown 文件预览插件

1. 实现新的 Markdown 预览插件,支持 text/markdown MIME 类型
2. 添加使用 QTextBrowser 的 MarkdownBrowser 控件,支持 Markdown 渲染
3. 创建预览上下文控件,包含适当的布局和样式
4. 实现文件读取功能,支持 5MB 大小限制和 UTF-8 编码
5. 添加插件检测机制,防止 text/* 插件拦截 text/markdown 文件
6. 支持使用基础目录解析相对图片路径

Log: 新增 Markdown 文件预览功能

Influence:
1. 测试不同大小和编码的 Markdown 文件预览
2. 验证 Markdown 渲染效果,包括标题、列表、链接和代码块
3. 测试 Markdown 文件中相对图片路径的解析
4. 验证当 text/markdown 和 text/* 插件同时存在时的优先级
5. 测试超过 5MB 文件的尺寸限制处理
6. 检查不同文件类型之间的预览切换
7. 验证 Markdown 内容中外部链接的处理
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Johnson-zs, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

这是一个添加了 Markdown 文件预览功能的代码变更。我来对代码进行审查:

  1. 代码结构和组织:
  • 新增的代码结构清晰,遵循了项目的现有架构
  • Markdown 预览功能被正确地组织为独立的插件
  • 文件划分合理,职责分明
  1. 主要改进建议:

a) 性能优化:

// markdownpreview.cpp
static constexpr qint64 kMaxReadSize { 1024 * 1024 * 5 };

建议将文件大小限制作为可配置参数,而不是硬编码。可以添加一个配置文件或使用系统设置。

b) 错误处理:

// markdownpreview.cpp
if (fileSize > kMaxReadSize) {
    fmDebug() << "Markdown preview: file size exceeds limit, truncating to:" << kMaxReadSize << "bytes";
}

当文件超过限制时,应该向用户显示明确的警告信息,而不仅仅是在日志中记录。

c) 内存管理:

// markdownpreview.cpp
~MarkdownPreview() {
    if (m_markdownBrowser) {
        m_markdownBrowser->setParent(nullptr);
        m_markdownBrowser->deleteLater();
        m_markdownBrowser = nullptr;
    }
}

建议使用 QPointer 来管理 m_markdownBrowser,这样可以自动处理对象删除问题。

d) 安全性:

// markdownpreview.cpp
QByteArray data = file.read(readSize);

应该添加对文件内容的验证,确保读取的内容是有效的 UTF-8 文本,避免潜在的编码问题。

e) 代码复用:

// filepreviewdialog.cpp
bool canReusePreview = false;
if (preview && !FileUtils::isDesktopFile(fileList.at(index))) {
    // ... 逻辑判断
}

建议将预览重用逻辑提取为单独的函数,提高代码可维护性。

f) 文档和注释:

  • 新增的类和方法需要更详细的文档说明
  • 关键业务逻辑应该添加更详细的注释说明
  1. 具体修改建议:
// markdownpreview.h
class MarkdownPreview : public DFMBASE_NAMESPACE::AbstractBasePreview
{
    Q_OBJECT
public:
    explicit MarkdownPreview(QObject *parent = nullptr);
    ~MarkdownPreview() override;

    // 添加配置方法
    static void setMaxFileSize(qint64 size);
    static qint64 maxFileSize();

private:
    QPointer<MarkdownContextWidget> m_markdownBrowser;  // 使用 QPointer
    static qint64 s_maxFileSize;  // 可配置的文件大小限制
};
// markdownpreview.cpp
qint64 MarkdownPreview::s_maxFileSize = 1024 * 1024 * 5;  // 默认 5MB

void MarkdownPreview::setMaxFileSize(qint64 size)
{
    s_maxFileSize = qMax(0LL, size);
}

qint64 MarkdownPreview::maxFileSize()
{
    return s_maxFileSize;
}

bool MarkdownPreview::setFileUrl(const QUrl &url)
{
    // ... 现有代码 ...

    if (fileSize > s_maxFileSize) {
        emit showWarning(tr("File size exceeds preview limit"));
        fmDebug() << "Markdown preview: file size exceeds limit, truncating to:" << s_maxFileSize << "bytes";
    }

    // 添加内容验证
    QTextCodec::ConverterState state;
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    const QString text = codec->toUnicode(data.constData(), data.size(), &state);
    if (state.invalidChars > 0) {
        fmWarning() << "Markdown preview: invalid UTF-8 content detected";
        return false;
    }

    // ... 其余代码 ...
}
  1. 其他建议:
  • 添加单元测试来验证 Markdown 预览功能
  • 考虑添加对 Markdown 扩展语法的支持
  • 添加对大文件的异步加载支持,避免 UI 阻塞

这些修改将提高代码的健壮性、可维护性和用户体验。

@Johnson-zs
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 4, 2025

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit 3421fbc into linuxdeepin:master Dec 4, 2025
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants