เราใช้การจัดรูปแบบ Font สำหรับบล็อกแบบอินไลน์ เมื่อไม่มีการโต้ตอบโดยตรงสำหรับคุณลักษณะ Markdown ใน Aspose.Words DOM เราจะใช้ลักษณะอักขระที่มีชื่อที่ขึ้นต้นด้วยคำพิเศษบางคำ
รายการสัญลักษณ์แสดงหัวข้อย่อยและลำดับคือคอนเทนเนอร์บล็อกใน Markdown เช่นกัน การซ้อนของพวกมันจะแสดงในรูปแบบ DOM เช่นเดียวกับบล็อกคอนเทนเนอร์อื่นๆ ทั้งหมดที่ใช้การสืบทอดสไตล์ อย่างไรก็ตาม นอกจากนี้ รายการใน DOM มีการจัดรูปแบบตัวเลขที่สอดคล้องกันในรูปแบบรายการหรือการจัดรูปแบบย่อหน้า
บล็อกแบบอินไลน์
เราใช้การจัดรูปแบบ Font เมื่อแปลคุณลักษณะ markdown แบบอินไลน์ Bold, Italic หรือ Strikethrough
คุณสมบัติ Markdown
Aspose.Words
Bold {1}
Font.bold = True
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()# Make the text Bold.builder.font.bold=Truebuilder.writeln("This text will be Bold")builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.bold_text_example.md")
Italic *italic text*
Font.italic = True
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()# Make the text Italic.builder.font.italic=Truebuilder.writeln("This text will be Italic")builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.italic_text_example.md")
Strikethrough ~Strikethrough text~
Font.strike_through = True
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()# Make the text Strikethrough.builder.font.strike_through=Truebuilder.writeln("This text will be Strikethrough")builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.strikethrough_text_example.md")
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()# Number of backticks is missed, one backtick will be used by default.inlineCode1BackTicks=builder.document.styles.add(aw.StyleType.CHARACTER,"InlineCode")builder.font.style=inlineCode1BackTicksbuilder.writeln("Text with InlineCode style with 1 backtick")# There will be 3 backticks.inlineCode3BackTicks=builder.document.styles.add(aw.StyleType.CHARACTER,"InlineCode.3")builder.font.style=inlineCode3BackTicksbuilder.writeln("Text with InlineCode style with 3 backtick")builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.inline_code_example.md")
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()# Insert hyperlink.builder.insert_hyperlink("https://www.aspose.com","https://www.aspose.com",False);builder.insert_hyperlink("email@aspose.com","mailto:email@aspose.com",False);builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.autolink_example.md")
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()# Insert hyperlink.builder.insert_hyperlink("Aspose","https://www.aspose.com",False)builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.link_example.md")
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()# Insert image.shape=aw.drawing.Shape(builder.document,aw.drawing.ShapeType.IMAGE)shape.wrap_type=aw.drawing.WrapType.INLINEshape.image_data.source_full_name="/attachment/1456/pic001.png"shape.image_data.title="title"builder.insert_node(shape)builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.image_example.md")
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
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
# Use a document builder to add content to the document.doc=aw.Document()builder=aw.DocumentBuilder(doc)builder.paragraph_format.style_name="Heading 1"builder.writeln("This is an H1 tag")# Reset styles from the previous paragraph to not combine styles between paragraphs.builder.font.bold=Falsebuilder.font.italic=FalsesetexHeading1=doc.styles.add(aw.StyleType.PARAGRAPH,"SetexHeading1")builder.paragraph_format.style=setexHeading1doc.styles.get_by_name("SetexHeading1").base_style_name="Heading 1"builder.writeln("Setex Heading level 1")builder.paragraph_format.style=doc.styles.get_by_name("Heading 3")builder.writeln("This is an H3 tag")# Reset styles from the previous paragraph to not combine styles between paragraphs.builder.font.bold=Falsebuilder.font.italic=FalsesetexHeading2=doc.styles.add(aw.StyleType.PARAGRAPH,"SetexHeading2")builder.paragraph_format.style=setexHeading2doc.styles.get_by_name("SetexHeading2").base_style_name="Heading 3"# Setex heading level will be reset to 2 if the base paragraph has a Heading level greater than 2.builder.writeln("Setex Heading level 2")builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.setext_heading_example.md")
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()indentedCode=builder.document.styles.add(aw.StyleType.PARAGRAPH,"IndentedCode")builder.paragraph_format.style=indentedCodebuilder.writeln("This is an indented code")builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.indented_code_example.md")
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()fencedCode=builder.document.styles.add(aw.StyleType.PARAGRAPH,"FencedCode")builder.paragraph_format.style=fencedCodebuilder.writeln("This is an fenced code")fencedCodeWithInfo=builder.document.styles.add(aw.StyleType.PARAGRAPH,"FencedCode.C#")builder.paragraph_format.style=fencedCodeWithInfobuilder.writeln("This is a fenced code with info string")builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.fenced_code_example.md")
# Use a document builder to add content to the document.doc=aw.Document()builder=aw.DocumentBuilder(doc)# By default a document stores blockquote style for the first level.builder.paragraph_format.style_name="Quote"builder.writeln("Blockquote")# Create styles for nested levels through style inheritance.quoteLevel2=doc.styles.add(aw.StyleType.PARAGRAPH,"Quote1")builder.paragraph_format.style=quoteLevel2doc.styles.get_by_name("Quote1").base_style_name="Quote"builder.writeln("1. Nested blockquote")builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.quote_example.md")
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()builder.list_format.apply_bullet_default()builder.list_format.list.list_levels[0].number_format="-"builder.writeln("Item 1")builder.writeln("Item 2")builder.list_format.list_indent()builder.writeln("Item 2a")builder.writeln("Item 2b")builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.bulleted_list_example.md")
# Use a document builder to add content to the document.builder=aw.DocumentBuilder()# Add the first row.builder.insert_cell()builder.writeln("a")builder.insert_cell()builder.writeln("b")builder.end_row()# Add the second row.builder.insert_cell()builder.writeln("c")builder.insert_cell()builder.writeln("d")builder.end_table()builder.document.save(docs_base.artifacts_dir+"WorkingWithMarkdown.ordered_list_table.md")