MarkDig use notes

tags: C#  markdown

I plan to make a tool for converting Markdown to docx. I found the C# parsing library MarkDig on the Internet. No Chinese example was found on the Internet. I wrote an analysis example of its table by reading its source code.

Note, if you want to parse the table, you need to add an extension

    var builder = (new Markdig.MarkdownPipelineBuilder());
    builder.Extensions.Add(new Markdig.Extensions.Tables.PipeTableExtension());
     var pipeline = builder.Build();

Parsing example:

            var doc = Markdig.Markdown.Parse("## Title 2 \r\n \r\n" +
                                 "|Header 1|Header 2|\r\n" +
                "|-----|-----|\r\n" +
                                 "|row 1 column 1|row 1 column 2|\r\n" +
                                 "|row 2 column 1|row 2 column 2|\r\n",
                pipeline

                );
            for (int i = 0; i < doc.Count; i++)
            {
                var b = doc[i];
                if (b is Markdig.Syntax.HeadingBlock)
                {
                    var heading = (Markdig.Syntax.HeadingBlock)b;
                    Console.WriteLine(heading.Level);
                    var containerInline = heading.Inline as Markdig.Syntax.Inlines.ContainerInline;
                    var literalInline = containerInline.FirstChild as Markdig.Syntax.Inlines.LiteralInline;
                    var stringSlice = literalInline.Content;

                    Console.WriteLine(stringSlice.Text.Substring(stringSlice.Start, stringSlice.Length));

                }
                else if (b is Markdig.Extensions.Tables.Table)
                {
                    var table = (Markdig.Extensions.Tables.Table)b;
                    for (int j = 0; j < table.Count; j++)
                    {
                        var row = (Markdig.Extensions.Tables.TableRow)table[j];
                        for (int k = 0; k < row.Count; k++)
                        {
                            var cell = (TableCell)row[k];
                            var containerInline = ((LeafBlock)cell[0]).Inline as Markdig.Syntax.Inlines.ContainerInline;
                            var literalInline = containerInline.FirstChild as Markdig.Syntax.Inlines.LiteralInline;
                            var stringSlice = literalInline.Content;

                            Console.WriteLine(stringSlice.Text.Substring(stringSlice.Start, stringSlice.Length));
                        }



                    }
                }
                else
                {
                }

           

              
            }


Intelligent Recommendation

Notes on the use of if tags in struts2

Q: Why won't the 'if' tag evaluate a one char string? A: If care is not taken with the quoting of literals, the expression language (OGNL) will misinterpret a char as a String. Wrong The solution is s...

Hibernate use important notes

Hibernate Usage Important Notes Hibernate API introduction: Configuration class SessionFactory interface: It is best to create only one factory (unless it is a multi-data source) Transaction interface...

Kafka use notes

When starting producers and consumers, they report an error: 1) View the Kafka configuration file, cat config/server.properties The connected zookeeper is localhost, so you need to start the productio...

Redis study notes - use

Article directory Connect redis Basic grammar Key String Connect redis Basic grammar Key # command effect 1 del key Delete key 2 dump key Serialize the key and return the serialized value 3 exists key...

C++ notes list use

List is a doubly linked list, header file #include<list> 1. Basic operation insert:Headend, tailend, middle (through iterators) Find:There is no member function, only the iterator can be returne...

More Recommendation

Hadoop notes (a) installation and use

1, must bind the host name and IP, otherwise the remote will not connect vi /etc/hosts 2, set ssh free login (1) ssh-keygen, always enter (2)ssh-copy-id localhost 3, install Java (1) Install jdk1.8: (...

Oracle use index in the notes

1. Use the unequal operator (<>, !=) In the following case, even if the column dept_id has an index, the query still performs a full table scan. select * from dept where staff_num <> 1000;...

FusioCharts use notes (2)

Thanks to Dowager A's FusionCharts Free Chinese Development Guide, I have taken a lot of detours. But there is still a difficulty, how to use smart strings and splicing dynamic data into dataXml in an...

Paperclip learning to use notes

     paperclip Is a plugin for rails processing attachments, compared to the pastattachment_fuWaiting for better efficiency and use.     paperclipUploaded image attachmen...

Notes on the actual use of undo

Need to delete large amounts of data from time to time because of work needs Due to the ability problem, I am afraid to schedule the deletion. And due to performance issues, only 4G undo tablespace on...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top