Chúng tôi rất vui mừng thông báo về việc phát hành GroupDocs.Markdown for .NET 26.3, có sẵn từ tháng 3 2026. Bản cập nhật lớn này giới thiệu một API công cộng được thiết kế lại, một bộ render Markdown dựa trên DOM tùy chỉnh, kiểm soát đầy đủ các biến thể Markdown, hỗ trợ async và một loạt các bản sửa lỗi. Nó cũng bổ sung các gói NuGet runtime theo từng TFM và hỗ trợ .NET 8 và .NET 10.
Những điểm mới trong phiên bản này
| Mã | Thể loại | Tóm tắt |
|---|---|---|
| MARKDOWNNET-33 | Feature | Split NuGet package into per-TFM runtime packages |
| MARKDOWNNET-31 | Feature | Add support for .NET 8 and .NET 10 |
| MARKDOWNNET-30 | Feature | Custom DOM-based Markdown renderer |
| MARKDOWNNET-29 | Feature | Conversion warnings and unified error model |
| MARKDOWNNET-28 | Feature | Relative image paths and image replacement |
| MARKDOWNNET-27 | Feature | Heading level offset and YAML front matter generation |
| MARKDOWNNET-26 | Feature | Markdown flavor control and spreadsheet rendering options |
| MARKDOWNNET-25 | Feature | Document inspection without conversion |
| MARKDOWNNET-24 | Feature | Async API |
| MARKDOWNNET-23 | Feature | Static convenience methods and format discovery |
| MARKDOWNNET-20 | Enhancement | Review and redesign the API |
| MARKDOWNNET-8 | Feature | Support for replacing images during conversion to Markdown |
| MARKDOWNNET-35 | Bug Fix | Quality and functional issues |
Thay đổi API công cộng
Các kiểu công cộng mới
DocumentInfo— siêu dữ liệu tài liệu (định dạng, số trang, tiêu đề, tác giả, trạng thái mã hóa)MarkdownFlavor— enum cho biến thể Markdown mục tiêu (GitHub, CommonMark)IImageSavingHandler— giao diện cho các callback lưu ảnh tùy chỉnhIUriSavingHandler— giao diện cho các callback lưu URI tùy chỉnhGroupDocsMarkdownException— ngoại lệ chuyển đổi chungInvalidFormatException— định dạng tệp hỏng hoặc không nhận dạng đượcDocumentProtectedException— mật khẩu sai hoặc thiếu
Các phương thức tĩnh mới trên MarkdownConverter
ToMarkdown(string sourcePath)and overloads withLoadOptions/ConvertOptionsToFile(string sourcePath, string outputPath)and overloadsGetInfo(string sourcePath)and overloadsGetSupportedFormats()- Async variants:
ToMarkdownAsync,ToFileAsync,GetInfoAsync
Các phương thức thực thể mới trên MarkdownConverter
GetDocumentInfo()ConvertAsync()and overloads
Các thuộc tính mới trên ConvertOptions
ImageExportStrategy(replacesExportStrategy)UriExportStrategyHeadingLevelOffsetIncludeFrontMatterFlavorMaxColumns,MaxRows,SheetSeparator,IncludeHiddenSheets
Các thuộc tính mới trên ConvertResult
Warnings— cảnh báo chuyển đổi không gây lỗi nghiêm trọng
Các thuộc tính mới trên ExportImagesToFileSystemStrategy và CustomImagesStrategy
ImagesRelativePath— điều khiển đường dẫn được ghi trong tham chiếu ảnh Markdown
Các phương thức mới trên CustomImageSavingArgs
SetReplacementImage(Stream imageStream)— thay thế nội dung ảnh
Các kiểu đã loại bỏ
IExportStrategy— được thay thế bằngIImageExportStrategyvàIUriExportStrategyDocumentConverterOptions— được đổi tên thànhConvertOptionsDocumentConverterResult— được đổi tên thànhConvertResult
Các thay đổi gây phá vỡ
Các kiểu được đổi tên
| Trước | Sau |
|---|---|
DocumentConverterOptions |
ConvertOptions |
DocumentConverterResult |
ConvertResult |
Enum FileFormat
Các giá trị cấp gia đình (FileFormat.WordProcessing, FileFormat.Spreadsheet) được thay thế bằng các định dạng cụ thể (FileFormat.Docx, FileFormat.Xlsx, v.v.). Các mục mới: FileFormat.Txt, FileFormat.Chm.
Tách ConvertOptions và LoadOptions
ConvertOptions không còn kế thừa LoadOptions. Mật khẩu và gợi ý định dạng được đặt trên LoadOptions:
var loadOptions = new LoadOptions(FileFormat.Docx) { Password = "secret" };
var convertOptions = new ConvertOptions { HeadingLevelOffset = 1 };
using var converter = new MarkdownConverter("file.docx", loadOptions);
var result = converter.Convert(convertOptions);
Tách chiến lược Image và URI
Thuộc tính ExportStrategy duy nhất được thay thế bằng hai thuộc tính kiểu riêng:
var options = new ConvertOptions
{
ImageExportStrategy = new ExportImagesToFileSystemStrategy("images"),
UriExportStrategy = new CustomUriExportStrategy(handler)
};
Delegate được thay thế bằng giao diện
CustomImagesStrategy và CustomUriExportStrategy hiện chấp nhận các giao diện IImageSavingHandler và IUriSavingHandler thay vì các callback delegate.
LoadOptions.Extension và LoadOptions.MimeType là nội bộ
Sử dụng new LoadOptions(FileFormat.Docx) thay vì thiết lập trực tiếp Extension hoặc MimeType.
Các tính năng mới
Bộ render Markdown dựa trên DOM tùy chỉnh
Thư viện không còn ủy thác việc tạo Markdown cho một công cụ xuất bên thứ ba. Bộ render tùy chỉnh duyệt mô hình đối tượng tài liệu (DOM) từng nút một và tạo ra Markdown trực tiếp, cung cấp kiểm soát đầy đủ mọi khía cạnh của đầu ra.
Tài liệu Word/PDF/Ebook/Text/CHM được render với hỗ trợ đoạn văn, tiêu đề (H1‑H6), in đậm, in nghiêng, gạch ngang, mã nội tuyến, danh sách có thứ tự và không thứ tự có phân cấp, bảng (cú pháp ống GFM hoặc fallback code block CommonMark), siêu liên kết và hình ảnh.
Bảng tính được render với việc duyệt lưới ô theo ô, định dạng giá trị có kiểu, các phần của worksheet, cắt ngắn cột/hàng với chỉ báo dấu ba chấm, lọc sheet ẩn và các dấu phân cách sheet tùy chỉnh.
Các phương thức tiện lợi tĩnh
Các phương thức chuyển đổi một dòng xử lý tự động quản lý tài nguyên:
string md = MarkdownConverter.ToMarkdown("report.docx");
MarkdownConverter.ToFile("report.docx", "report.md");
IReadOnlyList<FileFormat> formats = MarkdownConverter.GetSupportedFormats();
API Async
Các phiên bản async cho tất cả các phương thức tĩnh và thực thể với hỗ trợ CancellationToken:
string md = await MarkdownConverter.ToMarkdownAsync("report.docx");
await MarkdownConverter.ToFileAsync("large.pdf", "output.md");
DocumentInfo info = await MarkdownConverter.GetInfoAsync("report.docx");
Kiểm tra tài liệu mà không chuyển đổi
Lấy siêu dữ liệu tài liệu mà không thực hiện chuyển đổi đầy đủ:
DocumentInfo info = MarkdownConverter.GetInfo("report.docx");
Console.WriteLine($"{info.FileFormat}, {info.PageCount} pages, by {info.Author}");
Kiểm soát biến thể Markdown
Chọn một biến thể Markdown cụ thể:
var options = new ConvertOptions { Flavor = MarkdownFlavor.GitHub }; // pipe tables, strikethrough
var options = new ConvertOptions { Flavor = MarkdownFlavor.CommonMark }; // tables as code blocks
Tùy chọn render bảng tính
Kiểm soát đầy đủ cách bảng tính được render thành Markdown:
var options = new ConvertOptions
{
MaxColumns = 8,
MaxRows = 50,
SheetSeparator = "\n---\n",
IncludeHiddenSheets = false
};
Độ lệch cấp tiêu đề và YAML Front Matter
var options = new ConvertOptions
{
HeadingLevelOffset = 2, // # Title -> ### Title
IncludeFrontMatter = true // prepend YAML metadata
};
Cảnh báo chuyển đổi và mô hình lỗi thống nhất
Tất cả các phương thức Convert() hiện ném ngoại lệ khi thất bại. ConvertResult mang theo các cảnh báo không gây lỗi nghiêm trọng:
ConvertResult result = converter.Convert();
foreach (string w in result.Warnings)
Console.WriteLine(w); // e.g. "Worksheet 'Data' truncated at 50 rows."
Thay thế ảnh và đường dẫn tương đối
Thay thế ảnh trong quá trình chuyển đổi và kiểm soát đường dẫn tham chiếu:
var strategy = new ExportImagesToFileSystemStrategy("c:/output/images")
{
ImagesRelativePath = "images" // 
};
Render mục lục
Các tài liệu có Table of Contents được render thành danh sách sạch thay vì mã trường thô:
- Introduction
- 1. Executive Summary
- 2. Company Overview
Ví dụ mã
string md = MarkdownConverter.ToMarkdown("report.docx");
MarkdownConverter.ToFile("report.docx", "report.md");
IReadOnlyList<FileFormat> formats = MarkdownConverter.GetSupportedFormats();
Cách nhận bản cập nhật
NuGet
Nâng cấp lên gói GroupDocs.Markdown mới nhất qua NuGet (ví dụ, Install-Package GroupDocs.Markdown).