|
1 | 1 | using System; |
| 2 | +using Microsoft.Toolkit.Parsers.Markdown; |
| 3 | +using Microsoft.Toolkit.Parsers.Markdown.Blocks; |
2 | 4 |
|
3 | 5 | namespace md2docx |
4 | 6 | { |
5 | 7 | class Md2Docx |
6 | 8 | { |
7 | 9 | static void Main(String[] args) |
8 | 10 | { |
9 | | - Console.WriteLine("Hello Md2Docx!"); |
| 11 | + string md = System.IO.File.ReadAllText("test.md"); |
| 12 | + Console.WriteLine(md); |
| 13 | + |
| 14 | + MarkdownDocument mddoc = new MarkdownDocument(); |
| 15 | + mddoc.Parse(md); |
| 16 | + |
| 17 | + string name = ""; |
| 18 | + string id = ""; |
| 19 | + string teacher = ""; |
| 20 | + string department = ""; |
| 21 | + string title = ""; |
| 22 | + string clas = ""; |
| 23 | + |
| 24 | + foreach (var element in mddoc.Blocks) |
| 25 | + { |
| 26 | + if (element is YamlHeaderBlock yaml) |
| 27 | + { |
| 28 | + name = yaml.Children["name"]; |
| 29 | + id = yaml.Children["id"]; |
| 30 | + teacher = yaml.Children["teacher"]; |
| 31 | + department = yaml.Children["department"]; |
| 32 | + title = yaml.Children["title"]; |
| 33 | + clas = yaml.Children["class"]; |
| 34 | + } |
| 35 | + else if (element is ParagraphBlock para) |
| 36 | + { |
| 37 | + foreach (var e in para.Inlines) |
| 38 | + { |
| 39 | + Console.WriteLine($"Para({e.GetType()}) {e.ToString()}"); |
| 40 | + } |
| 41 | + } |
| 42 | + else if (element is ListBlock list) //我就操了为什么list里面可以放block,我丢 |
| 43 | + { |
| 44 | + foreach (var e in list.Items) |
| 45 | + { |
| 46 | + Console.WriteLine($"wtf({e.GetType()}) {e.Blocks[0].ToString()}"); |
| 47 | + } |
| 48 | + } |
| 49 | + else if (element is HeaderBlock head) |
| 50 | + { |
| 51 | + Console.Write($"H({head.HeaderLevel},)"); |
| 52 | + foreach (var e in head.Inlines) |
| 53 | + { |
| 54 | + Console.Write($"[{e.GetType()}, {e.ToString()}]"); |
| 55 | + } |
| 56 | + Console.WriteLine(""); |
| 57 | + } |
| 58 | + } |
| 59 | + Console.WriteLine($"name {name}"); |
| 60 | + Console.WriteLine($"id {id}"); |
| 61 | + Console.WriteLine($"teacher {teacher}"); |
| 62 | + Console.WriteLine($"department {department}"); |
| 63 | + Console.WriteLine($"title {title}"); |
| 64 | + Console.WriteLine($"class {clas}"); |
10 | 65 | } |
11 | 66 | } |
12 | 67 | } |
0 commit comments