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

Commit b32d6dc

Browse files
committed
refactor: refactor md2docx main body
with document update
1 parent b6ff93b commit b32d6dc

File tree

3 files changed

+294
-295
lines changed

3 files changed

+294
-295
lines changed

md2docx/GeneratedCode.cs

Lines changed: 173 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ public static LatentStyles GenerateLatentStyles()
787787

788788
return latentStyles;
789789
}
790-
790+
791791
public static void GenerateCover(ref Body docBody, Dictionary<string, string> info)
792792
{
793793
Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "003672AC", RsidParagraphProperties = "003672AC", RsidRunAdditionDefault = "003672AC", ParagraphId = "71725C42", TextId = "77777777" };
@@ -1687,7 +1687,7 @@ public static void GenerateCover(ref Body docBody, Dictionary<string, string> in
16871687

16881688
paragraphMarkRunProperties21.Append(runFonts27);
16891689
paragraphMarkRunProperties21.Append(fontSize38);
1690-
paragraphMarkRunProperties21.Append(fontSizeComplexScript27);
1690+
16911691

16921692
paragraphProperties21.Append(adjustRightIndent9);
16931693
paragraphProperties21.Append(snapToGrid9);
@@ -1898,5 +1898,176 @@ public static void GenerateCover(ref Body docBody, Dictionary<string, string> in
18981898
docBody.Append(paragraph27);
18991899
}
19001900

1901+
public static void GenerateTOC(ref Body docBody)
1902+
{
1903+
Paragraph para = new Paragraph
1904+
{
1905+
ParagraphProperties = new ParagraphProperties
1906+
{
1907+
ParagraphStyleId = new ParagraphStyleId { Val = "Abstract Title" },
1908+
PageBreakBefore = new PageBreakBefore()
1909+
}
1910+
};
1911+
Run run = new Run
1912+
{
1913+
RunProperties = new RunProperties()
1914+
};
1915+
Text txt = new Text { Text = "目录" };
1916+
run.Append(txt);
1917+
para.Append(run);
1918+
docBody.Append(para);
1919+
1920+
SdtBlock sdtBlock1 = new SdtBlock();
1921+
1922+
SdtProperties sdtProperties1 = new SdtProperties();
1923+
1924+
RunProperties runProperties1 = new RunProperties();
1925+
Languages languages1 = new Languages() { Val = "zh-CN" };
1926+
1927+
runProperties1.Append(languages1);
1928+
SdtId sdtId1 = new SdtId() { Val = 504253948 };
1929+
1930+
SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject();
1931+
DocPartGallery docPartGallery1 = new DocPartGallery() { Val = "Table of Contents" };
1932+
DocPartUnique docPartUnique1 = new DocPartUnique();
1933+
1934+
sdtContentDocPartObject1.Append(docPartGallery1);
1935+
sdtContentDocPartObject1.Append(docPartUnique1);
1936+
1937+
sdtProperties1.Append(runProperties1);
1938+
sdtProperties1.Append(sdtId1);
1939+
sdtProperties1.Append(sdtContentDocPartObject1);
1940+
1941+
SdtEndCharProperties sdtEndCharProperties1 = new SdtEndCharProperties();
1942+
1943+
RunProperties runProperties2 = new RunProperties();
1944+
RunFonts runFonts1 = new RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", EastAsia = "宋体", ComplexScript = "Times New Roman" };
1945+
Bold bold1 = new Bold();
1946+
BoldComplexScript boldComplexScript1 = new BoldComplexScript();
1947+
Color color1 = new Color() { Val = "auto" };
1948+
Kern kern1 = new Kern() { Val = (UInt32Value)2U };
1949+
FontSize fontSize1 = new FontSize() { Val = "24" };
1950+
FontSizeComplexScript fontSizeComplexScript1 = new FontSizeComplexScript() { Val = "24" };
1951+
1952+
runProperties2.Append(runFonts1);
1953+
runProperties2.Append(bold1);
1954+
runProperties2.Append(boldComplexScript1);
1955+
runProperties2.Append(color1);
1956+
runProperties2.Append(kern1);
1957+
runProperties2.Append(fontSize1);
1958+
runProperties2.Append(fontSizeComplexScript1);
1959+
1960+
sdtEndCharProperties1.Append(runProperties2);
1961+
1962+
SdtContentBlock sdtContentBlock1 = new SdtContentBlock();
1963+
1964+
Paragraph paragraph3 = new Paragraph() { RsidParagraphAddition = "003863DC", RsidRunAdditionDefault = "003863DC", ParagraphId = "233F4095", TextId = "52301D4D" };
1965+
1966+
SimpleField simpleField1 = new SimpleField() { Instruction = " TOC \\o \"1-3\" \\h \\z \\u " };
1967+
1968+
Run run4 = new Run();
1969+
1970+
RunProperties runProperties5 = new RunProperties
1971+
{
1972+
FontSize = new FontSize { Val = "24" },
1973+
FontSizeComplexScript = new FontSizeComplexScript { Val = "24" }
1974+
};
1975+
RunFonts runFonts2 = new RunFonts() { Hint = FontTypeHintValues.EastAsia };
1976+
Bold bold2 = new Bold();
1977+
BoldComplexScript boldComplexScript2 = new BoldComplexScript();
1978+
NoProof noProof1 = new NoProof();
1979+
1980+
runProperties5.Append(runFonts2);
1981+
runProperties5.Append(bold2);
1982+
runProperties5.Append(boldComplexScript2);
1983+
runProperties5.Append(noProof1);
1984+
Text text3 = new Text();
1985+
text3.Text = "请手动点击<更新目录>按钮更新目录";
1986+
1987+
run4.Append(runProperties5);
1988+
run4.Append(text3);
1989+
1990+
simpleField1.Append(run4);
1991+
1992+
paragraph3.Append(simpleField1);
1993+
1994+
sdtContentBlock1.Append(paragraph3);
1995+
1996+
sdtBlock1.Append(sdtProperties1);
1997+
sdtBlock1.Append(sdtEndCharProperties1);
1998+
sdtBlock1.Append(sdtContentBlock1);
1999+
2000+
docBody.Append(sdtBlock1);
2001+
}
2002+
2003+
public static void GenerateFontTablePartContent(FontTablePart fontTablePart1)
2004+
{
2005+
Fonts fonts1 = new Fonts() { MCAttributes = new MarkupCompatibilityAttributes() };
2006+
2007+
Font font1 = new Font() { Name = "Times New Roman" };
2008+
Panose1Number panose1Number1 = new Panose1Number() { Val = "02020603050405020304" };
2009+
FontCharSet fontCharSet1 = new FontCharSet() { Val = "00" };
2010+
FontFamily fontFamily1 = new FontFamily() { Val = FontFamilyValues.Roman };
2011+
Pitch pitch1 = new Pitch() { Val = FontPitchValues.Variable };
2012+
FontSignature fontSignature1 = new FontSignature() { UnicodeSignature0 = "E0002AFF", UnicodeSignature1 = "C0007843", UnicodeSignature2 = "00000009", UnicodeSignature3 = "00000000", CodePageSignature0 = "000001FF", CodePageSignature1 = "00000000" };
2013+
2014+
font1.Append(panose1Number1);
2015+
font1.Append(fontCharSet1);
2016+
font1.Append(fontFamily1);
2017+
font1.Append(pitch1);
2018+
font1.Append(fontSignature1);
2019+
2020+
Font font2 = new Font() { Name = "宋体" };
2021+
AltName altName1 = new AltName() { Val = "SimSun" };
2022+
Panose1Number panose1Number2 = new Panose1Number() { Val = "02010600030101010101" };
2023+
FontCharSet fontCharSet2 = new FontCharSet() { Val = "86" };
2024+
FontFamily fontFamily2 = new FontFamily() { Val = FontFamilyValues.Auto };
2025+
Pitch pitch2 = new Pitch() { Val = FontPitchValues.Variable };
2026+
FontSignature fontSignature2 = new FontSignature() { UnicodeSignature0 = "00000003", UnicodeSignature1 = "288F0000", UnicodeSignature2 = "00000016", UnicodeSignature3 = "00000000", CodePageSignature0 = "00040001", CodePageSignature1 = "00000000" };
2027+
2028+
font2.Append(altName1);
2029+
font2.Append(panose1Number2);
2030+
font2.Append(fontCharSet2);
2031+
font2.Append(fontFamily2);
2032+
font2.Append(pitch2);
2033+
font2.Append(fontSignature2);
2034+
2035+
Font font3 = new Font() { Name = "等线 Light" };
2036+
Panose1Number panose1Number3 = new Panose1Number() { Val = "02010600030101010101" };
2037+
FontCharSet fontCharSet3 = new FontCharSet() { Val = "86" };
2038+
FontFamily fontFamily3 = new FontFamily() { Val = FontFamilyValues.Auto };
2039+
Pitch pitch3 = new Pitch() { Val = FontPitchValues.Variable };
2040+
FontSignature fontSignature3 = new FontSignature() { UnicodeSignature0 = "A00002BF", UnicodeSignature1 = "38CF7CFA", UnicodeSignature2 = "00000016", UnicodeSignature3 = "00000000", CodePageSignature0 = "0004000F", CodePageSignature1 = "00000000" };
2041+
2042+
font3.Append(panose1Number3);
2043+
font3.Append(fontCharSet3);
2044+
font3.Append(fontFamily3);
2045+
font3.Append(pitch3);
2046+
font3.Append(fontSignature3);
2047+
2048+
Font font4 = new Font() { Name = "黑体" };
2049+
AltName altName2 = new AltName() { Val = "SimHei" };
2050+
Panose1Number panose1Number4 = new Panose1Number() { Val = "02010609060101010101" };
2051+
FontCharSet fontCharSet4 = new FontCharSet() { Val = "86" };
2052+
FontFamily fontFamily4 = new FontFamily() { Val = FontFamilyValues.Modern };
2053+
Pitch pitch4 = new Pitch() { Val = FontPitchValues.Fixed };
2054+
FontSignature fontSignature4 = new FontSignature() { UnicodeSignature0 = "800002BF", UnicodeSignature1 = "38CF7CFA", UnicodeSignature2 = "00000016", UnicodeSignature3 = "00000000", CodePageSignature0 = "00040001", CodePageSignature1 = "00000000" };
2055+
2056+
font4.Append(altName2);
2057+
font4.Append(panose1Number4);
2058+
font4.Append(fontCharSet4);
2059+
font4.Append(fontFamily4);
2060+
font4.Append(pitch4);
2061+
font4.Append(fontSignature4);
2062+
2063+
fonts1.Append(font1);
2064+
fonts1.Append(font2);
2065+
fonts1.Append(font3);
2066+
fonts1.Append(font4);
2067+
2068+
fontTablePart1.Fonts = fonts1;
2069+
}
2070+
2071+
19012072
}
19022073
}

md2docx/StyleFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ namespace md2docx
1010
{
1111
public class StyleFactory
1212
{
13+
/// <summary>
14+
/// Generate Style from JObject
15+
/// </summary>
16+
/// <param name="jObject">config json</param>
17+
/// <returns>correnspended style</returns>
1318
public Style GenerateStyle(JObject jObject)
1419
{
1520
string size;

0 commit comments

Comments
 (0)