함께 작업 Markdown 특징
이 항목에서는 구현 방법에 대해 설명합니다 Markdown 기능 사용 Aspose.Words. Markdown 쉽게 변환 할 수있는 일반 텍스트의 서식을 지정하는 간단한 방법입니다 HTML. Aspose.Words 다음을 지원합니다 Markdown 특징:
- 제목
- 인용구
- 수평 규칙
- 대담한 강조
- 기울임 꼴 강조
그 Markdown 기능 구현은 대부분 다음과 같습니다 CommonMark
안으로 명세 Aspose.Words API 그리고 모든 기능은 해당 스타일 또는 직접 형식으로 표시됩니다. 즉,
- 대문자와 이태릭은 다음과 같이 표시됩니다.
Font.Bold
그리고Font.Italic
. - 제목은 제목이 있는 단락입니다 1 -제목 6 스타일
- 따옴표는 스타일 이름에"따옴표"가 있는 단락입니다.
- HorizontalRule 이 단락은 HorizontalRule 모양.
Markdown 강조 표시가 있는 문서
이 섹션에서는 다음을 생성하는 방법을 보여 줍니다 markdown 아래와 같이 강조된 문서:
Markdown treats asterisks (*) and underscores (_) as indicators of emphasis.
You can write **bold** or *italic* text.
You can also write ***BoldItalic***text.
다음 코드 조각은 위의 주어진 것을 생성하는 데 사용될 수 있습니다. markdown 문서
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); | |
builder->Writeln(u"Markdown treats asterisks (*) and underscores (_) as indicators of emphasis."); | |
builder->Write(u"You can write "); | |
builder->get_Font()->set_Bold(true); | |
builder->Write(u"bold"); | |
builder->get_Font()->set_Bold(false); | |
builder->Write(u" or "); | |
builder->get_Font()->set_Italic(true); | |
builder->Write(u"italic"); | |
builder->get_Font()->set_Italic(false); | |
builder->Writeln(u" text. "); | |
builder->Write(u"You can also write "); | |
builder->get_Font()->set_Bold(true); | |
builder->get_Font()->set_Italic(true); | |
builder->Write(u"BoldItalic"); | |
builder->get_Font()->set_Bold(false); | |
builder->get_Font()->set_Italic(false); | |
builder->Write(u"text."); | |
System::String outputPath = outputDataDir + u"WorkingWithMarkdownFeatures.MarkdownDocumentWithEmphases.md"; | |
builder->get_Document()->Save(outputPath); |
Markdown 제목이 있는 문서
이 섹션에서는 다음을 생성하는 방법을 보여 줍니다 markdown 아래와 같이 제목이 있는 문서:
The following produces headings:
# Heading1
## Heading2
### Heading3
#### Heading4
##### Heading5
###### Heading6
# **Bold Heading1**
다음 코드 조각은 위의 주어진 것을 생성하는 데 사용될 수 있습니다. markdown 문서
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); | |
// By default Heading styles in Word may have bold and italic formatting. | |
// If we do not want text to be emphasized, set these properties explicitly to false. | |
builder->get_Font()->set_Bold(false); | |
builder->get_Font()->set_Italic(false); | |
builder->Writeln(u"The following produces headings:"); | |
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Heading 1")); | |
builder->Writeln(u"Heading1"); | |
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Heading 2")); | |
builder->Writeln(u"Heading2"); | |
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Heading 3")); | |
builder->Writeln(u"Heading3"); | |
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Heading 4")); | |
builder->Writeln(u"Heading4"); | |
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Heading 5")); | |
builder->Writeln(u"Heading5"); | |
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Heading 6")); | |
builder->Writeln(u"Heading6"); | |
// Note, emphases are also allowed inside Headings: | |
builder->get_Font()->set_Bold(true); | |
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Heading 1")); | |
builder->Writeln(u"Bold Heading1"); | |
System::String outputPath = outputDataDir + u"WorkingWithMarkdownFeatures.MarkdownDocumentWithHeadings.md"; | |
doc->Save(outputPath); |
Markdown 블록 따옴표가 있는 문서
이 섹션에서는 다음을 생성하는 방법을 보여 줍니다 markdown 아래에 주어진 블록 따옴표가있는 문서:
We support blockquotes in Markdown:
>*Lorem*
>*ipsum*
>The quotes can be of any level and can be nested:
>>>Quote level 3
>>>
>>>>Nested quote level 4
>
>*Back to first level*
>### Headings are allowed inside Quotes
>
다음 코드 조각은 위의 주어진 것을 생성하는 데 사용될 수 있습니다. markdown 문서
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); | |
builder->Writeln(u"We support blockquotes in Markdown:"); | |
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Quote")); | |
builder->Writeln(u"Lorem"); | |
builder->Writeln(u"ipsum"); | |
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Normal")); | |
builder->Writeln(u"The quotes can be of any level and can be nested:"); | |
System::SharedPtr<Style> quoteLevel3 = doc->get_Styles()->Add(Aspose::Words::StyleType::Paragraph, u"Quote2"); | |
builder->get_ParagraphFormat()->set_Style(quoteLevel3); | |
builder->Writeln(u"Quote level 3"); | |
System::SharedPtr<Style> quoteLevel4 = doc->get_Styles()->Add(Aspose::Words::StyleType::Paragraph, u"Quote3"); | |
builder->get_ParagraphFormat()->set_Style(quoteLevel4); | |
builder->Writeln(u"Nested quote level 4"); | |
builder->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Quote")); | |
builder->Writeln(); | |
builder->Writeln(u"Back to first level"); | |
System::SharedPtr<Style> quoteLevel1WithHeading = doc->get_Styles()->Add(Aspose::Words::StyleType::Paragraph, u"Quote Heading 3"); | |
builder->get_ParagraphFormat()->set_Style(quoteLevel1WithHeading); | |
builder->Write(u"Headings are allowed inside Quotes"); | |
System::String outputPath = outputDataDir + u"WorkingWithMarkdownFeatures.MarkdownDocumentWithBlockQuotes.md"; | |
doc->Save(outputPath); |
Markdown 수평 규칙이 있는 문서
이 섹션에서는 다음을 생성하는 방법을 보여 줍니다 markdown 아래와 같이 수평 규칙이 있는 문서:
We support Horizontal rules (Thematic breaks) in Markdown:
-----
다음 코드 조각은 위의 주어진 것을 생성하는 데 사용될 수 있습니다. markdown 문서
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(System::MakeObject<Document>()); | |
builder->Writeln(u"We support Horizontal rules (Thematic breaks) in Markdown:"); | |
builder->InsertHorizontalRule(); | |
System::String outputPath = outputDataDir + u"WorkingWithMarkdownFeatures.MarkdownDocumentWithHorizontalRule.md"; | |
builder->get_Document()->Save(outputPath); |
읽기 Markdown 문서
다음 코드 조각은 다음을 읽는 방법을 보여줍니다 markdown 문서
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
// This is Markdown document that was produced in example of UC3. | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"QuotesExample.md"); | |
// Let's remove Heading formatting from a Quote in the very last paragraph. | |
System::SharedPtr<Paragraph> paragraph = doc->get_FirstSection()->get_Body()->get_LastParagraph(); | |
paragraph->get_ParagraphFormat()->set_Style(doc->get_Styles()->idx_get(u"Quote")); | |
System::String outputPath = outputDataDir + u"WorkingWithMarkdownFeatures.ReadMarkdownDocument.md"; | |
doc->Save(outputPath); |
지정 Markdown 저장 옵션
Aspose.Words API 제공 MarkdownSaveOptions 문서를 저장하는 동안 추가 옵션을 지정하는 클래스 Markdown 형식
다음 코드 예제에서는 다양한 항목을 지정하는 방법을 보여 주었습니다 Markdown 저장 옵션.
auto builder = System::MakeObject<DocumentBuilder>(); | |
builder->Writeln(u"Some text!"); | |
// specify MarkDownSaveOptions | |
auto saveOptions = SaveOptions::CreateSaveOptions(SaveFormat::Markdown); | |
builder->get_Document()->Save(outputDataDir + u"TestDocument.md", saveOptions); |
내보내는 동안 테이블 내부의 콘텐츠를 정렬하는 방법 Markdown
Aspose.Words API 제공 TableContentAlignment 표의 내용을 정렬하는 선형 방향을 정의하는 열거형으로 Markdown 문서 다음 코드 예제에서는 테이블 내에서 콘텐츠를 정렬하는 방법을 보여 줍니다.
auto builder = System::MakeObject<DocumentBuilder>(); | |
// Create a new table with two cells. | |
builder->InsertCell(); | |
builder->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Right); | |
builder->Write(u"Cell1"); | |
builder->InsertCell(); | |
builder->get_ParagraphFormat()->set_Alignment(ParagraphAlignment::Center); | |
builder->Write(u"Cell2"); | |
auto saveOptions = System::MakeObject<MarkdownSaveOptions>(); | |
// Makes all paragraphs inside table to be aligned to Left. | |
saveOptions->set_TableContentAlignment(TableContentAlignment::Left); | |
builder->get_Document()->Save(outputDataDir + u"left.md", saveOptions); | |
// Makes all paragraphs inside table to be aligned to Right. | |
saveOptions->set_TableContentAlignment(TableContentAlignment::Right); | |
builder->get_Document()->Save(outputDataDir + u"right.md", saveOptions); | |
// Makes all paragraphs inside table to be aligned to Center. | |
saveOptions->set_TableContentAlignment(TableContentAlignment::Center); | |
builder->get_Document()->Save(outputDataDir + u"center.md", saveOptions); | |
// Makes all paragraphs inside table to be aligned automatically. | |
// The alignment in this case will be taken from the first paragraph in corresponding table column. | |
saveOptions->set_TableContentAlignment(TableContentAlignment::Auto); | |
builder->get_Document()->Save(outputDataDir + u"auto.md", saveOptions); |