xoofx / markdig

A fast, powerful, CommonMark compliant, extensible Markdown processor for .NET
BSD 2-Clause "Simplified" License
4.32k stars 448 forks source link

Style rendering is incomplete #794

Open Geek-Bob opened 5 months ago

Geek-Bob commented 5 months ago

code

        var str = "C#(发音为 \"C sharp\")是一种现代、面向对象的编程语言,由微软公司开发并在2000年首次发布,作为.NET框架的一部分。C#设计旨在提高开发效率,兼具强大的类型系统和现代编程特性,适用于从网页应用到桌面软件,再到游戏开发和企业级解决方案的广泛领域。\n\n### C# 的核心特性与概念\n\n#### 基础概念\n1. **强类型语言** - C#要求变量在使用前声明其类型,减少类型错误。\n2. **面向对象编程 (OOP)** - 支持类、对象、继承、封装、多态等概念。\n3. **垃圾回收 (GC)** - 自动管理内存,减少程序员手动分配和释放内存的工作。\n\n#### 进阶特性\n1. **LINQ (Language Integrated Query)** - 语言集成查询,允许以SQL类似的方式操作内存中的数据。\n2. **异步编程** - 使用async/await关键字简化异步操作的编写。\n3. **Lambda 表达式** - 简洁地定义匿名函数。\n4. **属性 (Properties)** - 提供访问私有字段的公共接口,支持数据验证逻辑。\n5. **泛型** - 支持编写可重用的类型安全的集合和方法。\n\n### C# 发展历程简表\n\n| 版本 | 发布年份 | 主要特性 |\n| --- | --- | --- |\n| 1.0 | 2002 | 初始版本,伴随.NET Framework 1.0发布 |\n| 2.0 | 2005 | 泛型、匿名方法、迭代器 |\n| 3.0 | 2007 | LINQ、Lambda表达式、隐式类型局部变量 |\n| 4.0 | 2010 | 动态类型、命名实参、异步编程模型的初步形态 |\n| 5.0 | 2012 | async/await、Caller Info Attributes |\n| 6.0 | 2015 | Roslyn编译器、字符串插值、异常过滤器 |\n| 7.0 | 2017 | 出栈变量、模式匹配、元组 |\n| 8.0 | 2019 | 默认接口方法、范围索引、可空引用类型 |\n| 9.0 | 2020 | 拓展方法上的顶级语句、目标类型新语法 |\n\n### Hello World 示例代码\n\n```csharp\nusing System;\n\nclass HelloWorld\n{\n    static void Main()\n    {\n        Console.WriteLine(\"Hello, World!\");\n    }\n}\n```\n\n在这段代码中,`using System;` 引入了System命名空间,其中包含Console类,用于输出文本到控制台。`Main` 方法是程序的入口点,而 `Console.WriteLine(\"Hello, World!\");` 这行代码则打印出经典的“Hello, World!”问候语。";
        var html = Markdown.ToHtml(str);

Problem description

For example: font title size, font background color, table border, table line background color, code block

Normal style

Snipaste_2024-04-30_14-22-51

[markdig] Style rendering

Snipaste_2024-04-30_14-42-54
MihaZupan commented 5 months ago

Things like tables aren't enabled by default. You must opt-in by adding additional extensions, e.g. UseAdvancedExtensions.

var pipeline = new MarkdownPipelineBuilder()
    .UseAdvancedExtensions()
    .Build();

string html = Markdown.ToHtml(content, pipeline);

Markdig won't add CSS for you -- styling is left up to you.

Geek-Bob commented 3 months ago

Sorry, I pasted the wrong code earlier, I was trying to convert Markdown to FlowDocument. My original code is:

FlowDocument  flowDocument =new Markdown().Transform(str);

But then I read your source code and found a solution, as follows:

var Engine = new Markdown();
var plugins = MdXamlPlugins.Default.Clone();
plugins.Syntax.And(SyntaxManager.MdXaml);
Engine.Plugins = plugins;
Engine.DocumentStyle = MarkdownStyle.Standard;
FlowDocument  flowDocument = Engine.Transform(str);

I wonder if this is a reasonable solution