Skip to content
This repository was archived by the owner on May 21, 2022. It is now read-only.

Commit 5dbd66f

Browse files
committed
feat: parse yaml for base information
1 parent 18e1943 commit 5dbd66f

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

md2docx/md2docx.cs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,67 @@
11
using System;
2+
using Microsoft.Toolkit.Parsers.Markdown;
3+
using Microsoft.Toolkit.Parsers.Markdown.Blocks;
24

35
namespace md2docx
46
{
57
class Md2Docx
68
{
79
static void Main(String[] args)
810
{
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}");
1065
}
1166
}
1267
}

0 commit comments

Comments
 (0)