แปลMarkdownไปยังรูปแบบวัตถุเอกสาร(DOM)
ในการอ่านจัดการและปรับเปลี่ยนเนื้อหาและการฟอร์แมตของเอกสารคุณต้องแปลไปยังโมเดลออบเจกต์ของเอกสารAspose.Words(DOM).
ในทางตรงกันข้ามกับเอกสารคำMarkdownไม่สอดคล้องกับDOMอธิบายไว้ใน Aspose.Wordsรูปแบบวัตถุเอกสาร(DOM) บทความ. อย่างไรก็ตามAspose.WordsมีกลไกของตัวเองสำหรับการแปลเอกสารMarkdownไปยังDOMและกลับ,เพื่อให้เราสามาร.
บทความนี้อธิบายวิธีการแปลคุณลักษณะต่างๆmarkdownเป็นAspose.WordsDOMและกลับไปยังรูปแบบMarkdown.
ความซับซ้อนของการแปลMarkdown – DOM – Markdown
ปัญหาหลักของกลไกนี้ไม่ได้เป็นเพียงการแปลMarkdownถึงDOMแต่ยังจะทำการเปลี่ยนแปลงย้อนกลับ-เพื่อบันทึกเอกสารกลับไปยังรูปแบบMarkdownที่มีการสูญเสียน้อยที่สุด มีองค์ประกอบเช่นคำพูดหลายระดับซึ่งการเปลี่ยนแปลงย้อนกลับไม่น่ารำคาญ.
เครื่องมือแปลของเราช่วยให้ผู้ใช้ไม่เพียงแต่ทำงานกับองค์ประกอบที่ซับซ้อนในเอกสารที่มีอยู่Markdownแต่ยังสร้างเอกสารของตนเองในรูปแบบของMarkdownด้วยโครงสร้างเดิมตั้งแต่เริ่มต้น เพื่อสร้างองค์ประกอบต่างๆคุณจำเป็นต้องใช้รูปแบบที่มีชื่อเฉพาะตามกฎระเบียบบางอย่างที่อธิบายไว้ในบทความนี้ รูปแบบดังกล่าวสามารถสร้างโปรแกรม.
หลักการแปลทั่วไป
เราใช้Fontการจัดรูปแบบสำหรับบล็อกแบบอินไลน์ เมื่อไม่มีการติดต่อโดยตรงสำหรับคุณลักษณะMarkdownในAspose.WordsDOMเราใช้รูปแบบตัวอักษรที่มีชื่อที่เริ่มต้นจาก.
สำหรับบล็อกคอนเทนเนอร์เราใช้มรดกสไตล์เพื่อแสดงคุณลักษณะMarkdownที่ซ้อนกัน ในกรณีนี้แม้ในขณะที่ไม่มีคุณลักษณะที่ซ้อนกัน,เรายังใช้รูปแบบย่อหน้าที่มีชื่อที่เริ่มต้นจากคำพิเศ.
รายการที่มีสัญลักษณ์แสดงหัวข้อย่อยและสั่งเป็นบล็อกคอนเทนเนอร์ในMarkdownเช่นกัน รทำรังของพวกเขาจะแสดงในDOMเช่นเดียวกับบล็อกคอนเทนเนอร์อื่นๆทั้งหมดโดยใช้การสืบทอ อย่างไรก็ตาม,นอกจากนี้,รายการในDOMมีการจัดรูปแบบตัวเลขที่สอดคล้องกันทั้งในรูปแบบราย.
บล็อกอินไลน์
เราใช้Fontการจัดรูปแบบเมื่อแปลBold,ItalicหรือStrikethroughอินไลน์markdownคุณสมบัติ.
Markdownคุณลักษณะ | Aspose.Words | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Bold**bold text** |
get_Font()->set_Bold(true) |
||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||
Italic*italic text* |
get_Font()->set_Italic(true) |
||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||
Strikethrough~Strikethrough text~ |
get_Font()->set_StrikeThrough(true) |
||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
เราใช้รูปแบบอักขระที่มีชื่อที่เริ่มต้นจากคำว่าInlineCode
ตามด้วยจุดเสริม(.)
และจำนวนของติ๊กหลัง(`)
สำหรับคุณลักษณะInlineCode
หากมีข้อผิดพลาดหลายข้อผิดพลาดจะมีการใช้เครื่องหมายย้อนกลับหนึ่งตัวโดยค่าเริ่มต้น.
Markdownคุณลักษณะ | Aspose.Words | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
InlineCode**inline code** |
get_Font()->set_StyleName(u"InlineCode[.][N]") |
||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||||||||||||||
Autolink<scheme://domain.com> <email@domain.com> |
คลาสFieldHyperlink. | ||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||||||||||||||
Link[link text](url) [link text](<url>"title") [link text](url 'title') [link text](url (title)) |
คลาสFieldHyperlink. | ||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||||||||||||||
Image   ) |
คลาสShape. | ||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
บล็อกคอนเทนเนอร์
เอกสารเป็นลำดับของคอนเทนเนอร์บล็อกเช่นส่วนหัวย่อหน้ารายการใบเสนอราคาและอื่ บล็อกคอนเทนเนอร์สามารถแบ่งออกเป็น2ชั้น:บล็อกใบและภาชนะบรรจุที่ซับซ้อน บล็อกใบสามารถมีเนื้อหาแบบอินไลน์เท่านั้น Contชนะบรรจุที่ซับซ้อนในที่สุดก็สามารถมีบล็อกภาชนะอื่นๆรวมทั้งบล็อกใบ.
บล็อกใบ
ตารางด้านล่างแสดงตัวอย่างการใช้บล็อกใบMarkdownในAspose.Words:
Markdownคุณลักษณะ | Aspose.Words | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
HorizontalRule----- |
นี่เป็นย่อหน้าง่ายๆที่มีรูปร่างHorizontalRuleที่สอดคล้องกัน:DocumentBuilder::InsertHorizontalRule() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ATX Heading# H1, ## H2, ### H3… |
get_ParagraphFormat()->set_StyleName(u"Heading N") ที่ไหน(1<=เอ็น <= 9).นี้ถูกแปลเป็นสไตล์ในตัวและควรจะตรงกับรูปแบบที่ระบุ(ไม่อนุญาตให้ต่อท้ายหรือคำนำหน้า) มิฉะนั้นมันจะเป็นเพียงย่อหน้าปกติที่มีสไตล์ที่สอดคล้องกัน. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Setext Heading=== (if Heading level 1),--- (if Heading level 2) |
get_ParagraphFormat->set_StyleName(u"SetextHeading[some suffix]") ขึ้นอยู่กับ"Heading N" สไตล์ถ้า(ยังไม่มีข้อความ>=2),แล้ว "Heading 2" จะถูกใช้,มิฉะนั้น"Heading 1" คำต่อท้ายใดๆที่ได้รับอนุญาตแต่ผู้นำเข้าAspose.Wordsใช้หมายเลข"1"และ"2"ตามลำดับ. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Indented Code | get_ParagraphFormat->set_StyleName(u"IndentedCode[some suffix]") |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Fenced Code
|
get_ParagraphFormat()->set_StyleName(u"FencedCode[.][info string]") [.] และ[info string] เป็นตัวเลือก. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Ersชนะบรรจุที่ซับซ้อน
ตารางด้านล่างแสดงตัวอย่างของการใช้Markdownคอนเทนเนอร์ที่ซับซ้อนในAspose.Words:
Markdownคุณลักษณะ | Aspose.Words | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Quote> quote, >> nested quote |
get_ParagraphFormat()->set_StyleName(u"Quote[some suffix]") ต่อท้ายในชื่อสไตล์เป็นตัวเลือกแต่ผู้นำเข้าAspose.Wordsใช้หมายเลขเรียงลำดับ1, 2, 3, …. ในกรณีของคำพูดที่ซ้อนกัน รังจะถูกกำหนดผ่านทางรูปแบบที่สืบทอด. |
||||||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||||||||||||||||||
BulletedList- Item 1 - Item 2 - Item 2a - Item 2b |
รายการที่มีสัญลักษณ์แสดงโดยใช้หมายเลขย่อหน้า:get_ListFormat()->ApplyBulletDefault() สามารถมี3ประเภทของรายการที่มีสัญลักษณ์ กต่างกันในรูปแบบตัวเลขของระดับแรกมาก เหล่านี้คือ: ‘-’ ,‘+’ หรือ‘*’ ตามลำดับ. |
||||||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
|||||||||||||||||||||||||||||||
OrderedList1. Item 1 2. Item 2 1) Item 2a 2) Item 2b |
รายการสั่งซื้อจะถูกแสดงโดยใช้หมายเลขย่อหน้า:get_ListFormat()->ApplyNumberDefault() สามารถมีเครื่องหมายรูปแบบหมายเลข2:‘.’และ‘)’ เครื่องหมายเริ่มต้นคือ‘.’. |
||||||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
โต๊ะ
Aspose.Wordsยังช่วยให้การแปลตารางเป็นDOMดังแสดงด้านล่าง:
Markdownคุณลักษณะ | Aspose.Words | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Table a|b -|- c|d |
Table,RowและCellชั้นเรียน. | ||||||||||||||||||||||||||||||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|