Class MarkdownSaveOptions

Class MarkdownSaveOptions

Namespace: Aspose.Words.Saving
Assembly: Aspose.Words.dll (25.12.0)

Class to specify additional options when saving a document into the Aspose.Words.SaveFormat.Markdown format.

To learn more, visit the Specify Save Options documentation article.

public class MarkdownSaveOptions : TxtSaveOptionsBase

Inheritance

object SaveOptions TxtSaveOptionsBase MarkdownSaveOptions

Inherited Members

TxtSaveOptionsBase.Encoding , TxtSaveOptionsBase.ParagraphBreak , TxtSaveOptionsBase.ForcePageBreaks , TxtSaveOptionsBase.ExportHeadersFootersMode , SaveOptions.CreateSaveOptions(SaveFormat) , SaveOptions.CreateSaveOptions(string) , SaveOptions.SaveFormat , SaveOptions.ExportGeneratorName , SaveOptions.TempFolder , SaveOptions.PrettyFormat , SaveOptions.UseAntiAliasing , SaveOptions.UseHighQualityRendering , SaveOptions.DmlRenderingMode , SaveOptions.DmlEffectsRenderingMode , SaveOptions.ImlRenderingMode , SaveOptions.DefaultTemplate , SaveOptions.UpdateFields , SaveOptions.UpdateLastSavedTimeProperty , SaveOptions.UpdateLastPrintedProperty , SaveOptions.UpdateCreatedTimeProperty , SaveOptions.MemoryOptimization , SaveOptions.UpdateAmbiguousTextFont , SaveOptions.Dml3DEffectsRenderingMode , SaveOptions.ProgressCallback , SaveOptions.AllowEmbeddingPostScriptFonts , SaveOptions.CustomTimeZoneInfo , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

Shows how to rename the image name during saving into Markdown document.

public void RenameImages()
                                                                                   {
                                                                                       Document doc = new Document(MyDir + "Rendering.docx");

                                                                                       MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                                                       // If we convert a document that contains images into Markdown, we will end up with one Markdown file which links to several images.
                                                                                       // Each image will be in the form of a file in the local file system.
                                                                                       // There is also a callback that can customize the name and file system location of each image.
                                                                                       saveOptions.ImageSavingCallback = new SavedImageRename("MarkdownSaveOptions.HandleDocument.md");
                                                                                       saveOptions.SaveFormat = SaveFormat.Markdown;

                                                                                       // The ImageSaving() method of our callback will be run at this time.
                                                                                       doc.Save(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md", saveOptions);

                                                                                       Assert.That(Directory.GetFiles(ArtifactsDir)
                                                                                               .Where(s => s.StartsWith(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md shape"))
                                                                                               .Count(f => f.EndsWith(".jpeg")), Is.EqualTo(1));
                                                                                       Assert.That(Directory.GetFiles(ArtifactsDir)
                                                                                               .Where(s => s.StartsWith(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md shape"))
                                                                                               .Count(f => f.EndsWith(".png")), Is.EqualTo(8));
                                                                                   }

                                                                                   /// <summary>
                                                                                   /// Renames saved images that are produced when an Markdown document is saved.
                                                                                   /// </summary>
                                                                                   public class SavedImageRename : IImageSavingCallback
                                                                                   {
                                                                                       public SavedImageRename(string outFileName)
                                                                                       {
                                                                                           mOutFileName = outFileName;
                                                                                       }

                                                                                       void IImageSavingCallback.ImageSaving(ImageSavingArgs args)
                                                                                       {
                                                                                           string imageFileName = $"{mOutFileName} shape {++mCount}, of type {args.CurrentShape.ShapeType}{Path.GetExtension(args.ImageFileName)}";

                                                                                           args.ImageFileName = imageFileName;
                                                                                           args.ImageStream = new FileStream(ArtifactsDir + imageFileName, FileMode.Create);

                                                                                           Assert.That(args.ImageStream.CanWrite, Is.True);
                                                                                           Assert.That(args.IsImageAvailable, Is.True);
                                                                                           Assert.That(args.KeepImageStreamOpen, Is.False);
                                                                                       }

                                                                                       private int mCount;
                                                                                       private readonly string mOutFileName;
                                                                                   }

Constructors

MarkdownSaveOptions()

Initializes a new instance of this class that can be used to save a document in the Aspose.Words.SaveFormat.Markdown format.

public MarkdownSaveOptions()

Examples

Shows how to rename the image name during saving into Markdown document.

public void RenameImages()
                                                                                   {
                                                                                       Document doc = new Document(MyDir + "Rendering.docx");

                                                                                       MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                                                       // If we convert a document that contains images into Markdown, we will end up with one Markdown file which links to several images.
                                                                                       // Each image will be in the form of a file in the local file system.
                                                                                       // There is also a callback that can customize the name and file system location of each image.
                                                                                       saveOptions.ImageSavingCallback = new SavedImageRename("MarkdownSaveOptions.HandleDocument.md");
                                                                                       saveOptions.SaveFormat = SaveFormat.Markdown;

                                                                                       // The ImageSaving() method of our callback will be run at this time.
                                                                                       doc.Save(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md", saveOptions);

                                                                                       Assert.That(Directory.GetFiles(ArtifactsDir)
                                                                                               .Where(s => s.StartsWith(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md shape"))
                                                                                               .Count(f => f.EndsWith(".jpeg")), Is.EqualTo(1));
                                                                                       Assert.That(Directory.GetFiles(ArtifactsDir)
                                                                                               .Where(s => s.StartsWith(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md shape"))
                                                                                               .Count(f => f.EndsWith(".png")), Is.EqualTo(8));
                                                                                   }

                                                                                   /// <summary>
                                                                                   /// Renames saved images that are produced when an Markdown document is saved.
                                                                                   /// </summary>
                                                                                   public class SavedImageRename : IImageSavingCallback
                                                                                   {
                                                                                       public SavedImageRename(string outFileName)
                                                                                       {
                                                                                           mOutFileName = outFileName;
                                                                                       }

                                                                                       void IImageSavingCallback.ImageSaving(ImageSavingArgs args)
                                                                                       {
                                                                                           string imageFileName = $"{mOutFileName} shape {++mCount}, of type {args.CurrentShape.ShapeType}{Path.GetExtension(args.ImageFileName)}";

                                                                                           args.ImageFileName = imageFileName;
                                                                                           args.ImageStream = new FileStream(ArtifactsDir + imageFileName, FileMode.Create);

                                                                                           Assert.That(args.ImageStream.CanWrite, Is.True);
                                                                                           Assert.That(args.IsImageAvailable, Is.True);
                                                                                           Assert.That(args.KeepImageStreamOpen, Is.False);
                                                                                       }

                                                                                       private int mCount;
                                                                                       private readonly string mOutFileName;
                                                                                   }

Properties

EmptyParagraphExportMode

Specifies how to export empty paragraphs to Markdown. Default value is Aspose.Words.Saving.MarkdownEmptyParagraphExportMode.EmptyLine.

public MarkdownEmptyParagraphExportMode EmptyParagraphExportMode { get; set; }

Property Value

MarkdownEmptyParagraphExportMode

Examples

Shows how to export empty paragraphs.

Document doc = new Document();
                                                DocumentBuilder builder = new DocumentBuilder(doc);
                                                builder.Writeln("First");
                                                builder.Writeln("\r\n\r\n\r\n");
                                                builder.Writeln("Last");

                                                MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                saveOptions.EmptyParagraphExportMode = exportMode;

                                                doc.Save(ArtifactsDir + "MarkdownSaveOptions.EmptyParagraphExportMode.md", saveOptions);

                                                string result = File.ReadAllText(ArtifactsDir + "MarkdownSaveOptions.EmptyParagraphExportMode.md");

                                                switch (exportMode)
                                                {
                                                    case MarkdownEmptyParagraphExportMode.None:
                                                        Assert.That(result, Is.EqualTo("First\r\n\r\nLast\r\n"));
                                                        break;
                                                    case MarkdownEmptyParagraphExportMode.EmptyLine:
                                                        Assert.That(result, Is.EqualTo("First\r\n\r\n\r\n\r\n\r\nLast\r\n\r\n"));
                                                        break;
                                                    case MarkdownEmptyParagraphExportMode.MarkdownHardLineBreak:
                                                        Assert.That(result, Is.EqualTo("First\r\n\\\r\n\\\r\n\\\r\n\\\r\n\\\r\nLast\r\n<br>\r\n"));
                                                        break;
                                                }

ExportAsHtml

Allows to specify the elements to be exported to Markdown as raw HTML. Default value is Aspose.Words.Saving.MarkdownExportAsHtml.None.

public MarkdownExportAsHtml ExportAsHtml { get; set; }

Property Value

MarkdownExportAsHtml

Examples

Shows how to export a table to Markdown as raw HTML.

Document doc = new Document();
                                                               DocumentBuilder builder = new DocumentBuilder(doc);

                                                               builder.Writeln("Sample table:");

                                                               // Create table.
                                                               builder.InsertCell();
                                                               builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
                                                               builder.Write("Cell1");
                                                               builder.InsertCell();
                                                               builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
                                                               builder.Write("Cell2");

                                                               MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                               saveOptions.ExportAsHtml = MarkdownExportAsHtml.Tables;

                                                               doc.Save(ArtifactsDir + "MarkdownSaveOptions.ExportTableAsHtml.md", saveOptions);

ExportImagesAsBase64

Specifies whether images are saved in Base64 format to the output file. Default value is false.

public bool ExportImagesAsBase64 { get; set; }

Property Value

bool

Examples

Shows how to save a .md document with images embedded inside it.

Document doc = new Document(MyDir + "Images.docx");

                                                                           MarkdownSaveOptions saveOptions = new MarkdownSaveOptions { ExportImagesAsBase64 = exportImagesAsBase64 };

                                                                           doc.Save(ArtifactsDir + "MarkdownSaveOptions.ExportImagesAsBase64.md", saveOptions);

                                                                           string outDocContents = File.ReadAllText(ArtifactsDir + "MarkdownSaveOptions.ExportImagesAsBase64.md");

                                                                           Assert.That(exportImagesAsBase64
                                                                               ? outDocContents.Contains("data:image/jpeg;base64")
                                                                               : outDocContents.Contains("MarkdownSaveOptions.ExportImagesAsBase64.001.jpeg"), Is.True);

Remarks

When this property is set to true images data are exported directly into the img elements and separate files are not created.

ExportUnderlineFormatting

Gets or sets a boolean value indicating either to export underline text formatting as sequence of two plus characters “++”. The default value is false.

public bool ExportUnderlineFormatting { get; set; }

Property Value

bool

Examples

Shows how to export underline formatting as ++.

Document doc = new Document();
                                                          DocumentBuilder builder = new DocumentBuilder(doc);

                                                          builder.Underline = Underline.Single;
                                                          builder.Write("Lorem ipsum. Dolor sit amet.");

                                                          MarkdownSaveOptions saveOptions = new MarkdownSaveOptions() { ExportUnderlineFormatting = true };
                                                          doc.Save(ArtifactsDir + "MarkdownSaveOptions.ExportUnderlineFormatting.md", saveOptions);

ImageResolution

Specifies the output resolution for images when exporting to Markdown. Default is 96 dpi.

public int ImageResolution { get; set; }

Property Value

int

Examples

Shows how to set the output resolution for images.

Document doc = new Document(MyDir + "Rendering.docx");

                                                             MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                             saveOptions.ImageResolution = 300;

                                                             doc.Save(ArtifactsDir + "MarkdownSaveOptions.ImageResolution.md", saveOptions);

ImageSavingCallback

Allows to control how images are saved when a document is saved to Aspose.Words.SaveFormat.Markdown format.

public IImageSavingCallback ImageSavingCallback { get; set; }

Property Value

IImageSavingCallback

Examples

Shows how to rename the image name during saving into Markdown document.

public void RenameImages()
                                                                                   {
                                                                                       Document doc = new Document(MyDir + "Rendering.docx");

                                                                                       MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                                                       // If we convert a document that contains images into Markdown, we will end up with one Markdown file which links to several images.
                                                                                       // Each image will be in the form of a file in the local file system.
                                                                                       // There is also a callback that can customize the name and file system location of each image.
                                                                                       saveOptions.ImageSavingCallback = new SavedImageRename("MarkdownSaveOptions.HandleDocument.md");
                                                                                       saveOptions.SaveFormat = SaveFormat.Markdown;

                                                                                       // The ImageSaving() method of our callback will be run at this time.
                                                                                       doc.Save(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md", saveOptions);

                                                                                       Assert.That(Directory.GetFiles(ArtifactsDir)
                                                                                               .Where(s => s.StartsWith(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md shape"))
                                                                                               .Count(f => f.EndsWith(".jpeg")), Is.EqualTo(1));
                                                                                       Assert.That(Directory.GetFiles(ArtifactsDir)
                                                                                               .Where(s => s.StartsWith(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md shape"))
                                                                                               .Count(f => f.EndsWith(".png")), Is.EqualTo(8));
                                                                                   }

                                                                                   /// <summary>
                                                                                   /// Renames saved images that are produced when an Markdown document is saved.
                                                                                   /// </summary>
                                                                                   public class SavedImageRename : IImageSavingCallback
                                                                                   {
                                                                                       public SavedImageRename(string outFileName)
                                                                                       {
                                                                                           mOutFileName = outFileName;
                                                                                       }

                                                                                       void IImageSavingCallback.ImageSaving(ImageSavingArgs args)
                                                                                       {
                                                                                           string imageFileName = $"{mOutFileName} shape {++mCount}, of type {args.CurrentShape.ShapeType}{Path.GetExtension(args.ImageFileName)}";

                                                                                           args.ImageFileName = imageFileName;
                                                                                           args.ImageStream = new FileStream(ArtifactsDir + imageFileName, FileMode.Create);

                                                                                           Assert.That(args.ImageStream.CanWrite, Is.True);
                                                                                           Assert.That(args.IsImageAvailable, Is.True);
                                                                                           Assert.That(args.KeepImageStreamOpen, Is.False);
                                                                                       }

                                                                                       private int mCount;
                                                                                       private readonly string mOutFileName;
                                                                                   }

ImagesFolder

Specifies the physical folder where images are saved when exporting a document to the Aspose.Words.SaveFormat.Markdown format. Default is an empty string.

public string ImagesFolder { get; set; }

Property Value

string

Examples

Shows how to specifies the name of the folder used to construct image URIs.

DocumentBuilder builder = new DocumentBuilder();

                                                                                      builder.Writeln("Some image below:");
                                                                                      builder.InsertImage(ImageDir + "Logo.jpg");

                                                                                      string imagesFolder = Path.Combine(ArtifactsDir, "ImagesDir");
                                                                                      MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                                                      // Use the "ImagesFolder" property to assign a folder in the local file system into which
                                                                                      // Aspose.Words will save all the document's linked images.
                                                                                      saveOptions.ImagesFolder = imagesFolder;
                                                                                      // Use the "ImagesFolderAlias" property to use this folder
                                                                                      // when constructing image URIs instead of the images folder's name.
                                                                                      saveOptions.ImagesFolderAlias = "http://example.com/images";

                                                                                      builder.Document.Save(ArtifactsDir + "MarkdownSaveOptions.ImagesFolder.md", saveOptions);

Remarks

When you save a Aspose.Words.Document in Aspose.Words.SaveFormat.Markdown format, Aspose.Words needs to save all images embedded in the document as standalone files. Aspose.Words.Saving.MarkdownSaveOptions.ImagesFolder allows you to specify where the images will be saved.

If you save a document into a file and provide a file name, Aspose.Words, by default, saves the images in the same folder where the document file is saved. Use Aspose.Words.Saving.MarkdownSaveOptions.ImagesFolder to override this behavior.

If you save a document into a stream, Aspose.Words does not have a folder where to save the images, but still needs to save the images somewhere. In this case, you need to specify an accessible folder in the Aspose.Words.Saving.MarkdownSaveOptions.ImagesFolder property.

If the folder specified by Aspose.Words.Saving.MarkdownSaveOptions.ImagesFolder doesn't exist, it will be created automatically.

ImagesFolderAlias

Specifies the name of the folder used to construct image URIs written into a document. Default is an empty string.

public string ImagesFolderAlias { get; set; }

Property Value

string

Examples

Shows how to specifies the name of the folder used to construct image URIs.

DocumentBuilder builder = new DocumentBuilder();

                                                                                      builder.Writeln("Some image below:");
                                                                                      builder.InsertImage(ImageDir + "Logo.jpg");

                                                                                      string imagesFolder = Path.Combine(ArtifactsDir, "ImagesDir");
                                                                                      MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                                                      // Use the "ImagesFolder" property to assign a folder in the local file system into which
                                                                                      // Aspose.Words will save all the document's linked images.
                                                                                      saveOptions.ImagesFolder = imagesFolder;
                                                                                      // Use the "ImagesFolderAlias" property to use this folder
                                                                                      // when constructing image URIs instead of the images folder's name.
                                                                                      saveOptions.ImagesFolderAlias = "http://example.com/images";

                                                                                      builder.Document.Save(ArtifactsDir + "MarkdownSaveOptions.ImagesFolder.md", saveOptions);

Remarks

When you save a Aspose.Words.Document in Aspose.Words.SaveFormat.Markdown format, Aspose.Words needs to save all images embedded in the document as standalone files. Aspose.Words.Saving.MarkdownSaveOptions.ImagesFolder allows you to specify where the images will be saved and Aspose.Words.Saving.MarkdownSaveOptions.ImagesFolderAlias allows to specify how the image URIs will be constructed.

If Aspose.Words.Saving.MarkdownSaveOptions.ImagesFolderAlias is not an empty string, then the image URI written to Markdown will be ImagesFolderAlias + <image file name>.

If Aspose.Words.Saving.MarkdownSaveOptions.ImagesFolderAlias is an empty string, then the image URI written to Markdown will be ImagesFolder + <image file name>.

If Aspose.Words.Saving.MarkdownSaveOptions.ImagesFolderAlias is set to '.' (dot), then the image file name will be written to Markdown without path regardless of other options.

Aspose.Words.Saving.MarkdownSaveOptions.ImagesFolder Aspose.Words.Saving.MarkdownSaveOptions.ImageSavingCallback

LinkExportMode

Specifies how links will be written to the output file. Default value is Aspose.Words.Saving.MarkdownLinkExportMode.Auto.

public MarkdownLinkExportMode LinkExportMode { get; set; }

Property Value

MarkdownLinkExportMode

Examples

Shows how to links will be written to the .md file.

Document doc = new Document();
                                                              DocumentBuilder builder = new DocumentBuilder(doc);
                                                              builder.InsertShape(ShapeType.Balloon, 100, 100);

                                                              // Image will be written as reference:
                                                              // ![ref1]
                                                              //
                                                              // [ref1]: aw_ref.001.png
                                                              MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                              saveOptions.LinkExportMode = MarkdownLinkExportMode.Reference;
                                                              doc.Save(ArtifactsDir + "MarkdownSaveOptions.LinkExportMode.Reference.md", saveOptions);

                                                              // Image will be written as inline:
                                                              // ![](aw_inline.001.png)
                                                              saveOptions.LinkExportMode = MarkdownLinkExportMode.Inline;
                                                              doc.Save(ArtifactsDir + "MarkdownSaveOptions.LinkExportMode.Inline.md", saveOptions);

ListExportMode

Specifies how list items will be written to the output file. Default value is Aspose.Words.Saving.MarkdownListExportMode.MarkdownSyntax.

public MarkdownListExportMode ListExportMode { get; set; }

Property Value

MarkdownListExportMode

Examples

Shows how to list items will be written to the markdown document.

Document doc = new Document(MyDir + "List item.docx");

                                                                            // Use MarkdownListExportMode.PlainText or MarkdownListExportMode.MarkdownSyntax to export list.
                                                                            MarkdownSaveOptions options = new MarkdownSaveOptions { ListExportMode = markdownListExportMode };
                                                                            doc.Save(ArtifactsDir + "MarkdownSaveOptions.ListExportMode.md", options);

Remarks

When this property is set to Aspose.Words.Saving.MarkdownListExportMode.PlainText all list labels are updated using Aspose.Words.Document.UpdateListLabels and exported with their actual values. Such lists can be non-compatible with Markdown format and will be recognized as plain text upon importing in this case.

When this property is set to Aspose.Words.Saving.MarkdownListExportMode.MarkdownSyntax, writer tries to export list items in manner that allows to numerate list items in automatic mode by Markdown.

OfficeMathExportMode

Specifies how OfficeMath will be written to the output file. Default value is Aspose.Words.Saving.MarkdownOfficeMathExportMode.Text.

public MarkdownOfficeMathExportMode OfficeMathExportMode { get; set; }

Property Value

MarkdownOfficeMathExportMode

Examples

Shows how OfficeMath will be written to the document.

Document doc = new Document(MyDir + "Office math.docx");

                                                                MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                                saveOptions.OfficeMathExportMode = MarkdownOfficeMathExportMode.Image;

                                                                doc.Save(ArtifactsDir + "MarkdownSaveOptions.OfficeMathExportMode.md", saveOptions);

Shows how to export OfficeMath object as Latex.

Document doc = new Document(MyDir + "Office math.docx");

                                                          MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                          saveOptions.OfficeMathExportMode = MarkdownOfficeMathExportMode.Latex;

                                                          doc.Save(ArtifactsDir + "MarkdownSaveOptions.ExportOfficeMathAsLatex.md", saveOptions);

Shows how to export OfficeMath object as MarkItDown.

Document doc = new Document(MyDir + "Office math.docx");

                                                               MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                               saveOptions.OfficeMathExportMode = MarkdownOfficeMathExportMode.MarkItDown;

                                                               doc.Save(ArtifactsDir + "MarkdownSaveOptions.ExportOfficeMathAsMarkItDown.md", saveOptions);

ResourceSavingCallback

Allows to control how resources are saved when a document is exported to Aspose.Words.SaveFormat.Markdown format.

public IResourceSavingCallback ResourceSavingCallback { get; set; }

Property Value

IResourceSavingCallback

Examples

Shows how to use a callback to change the resource URI.

public void ResourceSavingCallback()
                                                                  {
                                                                      string outputPath = ArtifactsDir + "MarkdownSaveOptions.ResourceSavingCallback.md";

                                                                      Document doc = new Document(MyDir + "Rendering.docx");

                                                                      MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                                      saveOptions.ResourceSavingCallback = new ChangeUriPath();

                                                                      doc.Save(outputPath, saveOptions);

                                                                      DocumentHelper.FindTextInFile(outputPath, "/uri/for/");
                                                                  }

                                                                  /// <summary>
                                                                  /// Class implementing <see cref="IResourceSavingCallback"/>.
                                                                  /// </summary>
                                                                  private class ChangeUriPath : IResourceSavingCallback
                                                                  {
                                                                      public void ResourceSaving(ResourceSavingArgs args)
                                                                      {
                                                                          args.ResourceFileUri = string.Format("/uri/for/{0}", args.ResourceFileName);
                                                                      }
                                                                  }

Remarks

Note, there is only one type of resources in Markdown. These are images. When you specify both Aspose.Words.Saving.MarkdownSaveOptions.ImageSavingCallback and Aspose.Words.Saving.MarkdownSaveOptions.ResourceSavingCallback, then first is called Aspose.Words.Saving.MarkdownSaveOptions.ResourceSavingCallback. However, note it is not necessary to have both implementations, as Aspose.Words.Saving.ImageSavingArgs is actually a subset of Aspose.Words.Saving.ResourceSavingArgs.

SaveFormat

Specifies the format in which the document will be saved if this save options object is used. Can only be Aspose.Words.SaveFormat.Markdown.

public override SaveFormat SaveFormat { get; set; }

Property Value

SaveFormat

Examples

Shows how to rename the image name during saving into Markdown document.

public void RenameImages()
                                                                                   {
                                                                                       Document doc = new Document(MyDir + "Rendering.docx");

                                                                                       MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
                                                                                       // If we convert a document that contains images into Markdown, we will end up with one Markdown file which links to several images.
                                                                                       // Each image will be in the form of a file in the local file system.
                                                                                       // There is also a callback that can customize the name and file system location of each image.
                                                                                       saveOptions.ImageSavingCallback = new SavedImageRename("MarkdownSaveOptions.HandleDocument.md");
                                                                                       saveOptions.SaveFormat = SaveFormat.Markdown;

                                                                                       // The ImageSaving() method of our callback will be run at this time.
                                                                                       doc.Save(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md", saveOptions);

                                                                                       Assert.That(Directory.GetFiles(ArtifactsDir)
                                                                                               .Where(s => s.StartsWith(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md shape"))
                                                                                               .Count(f => f.EndsWith(".jpeg")), Is.EqualTo(1));
                                                                                       Assert.That(Directory.GetFiles(ArtifactsDir)
                                                                                               .Where(s => s.StartsWith(ArtifactsDir + "MarkdownSaveOptions.HandleDocument.md shape"))
                                                                                               .Count(f => f.EndsWith(".png")), Is.EqualTo(8));
                                                                                   }

                                                                                   /// <summary>
                                                                                   /// Renames saved images that are produced when an Markdown document is saved.
                                                                                   /// </summary>
                                                                                   public class SavedImageRename : IImageSavingCallback
                                                                                   {
                                                                                       public SavedImageRename(string outFileName)
                                                                                       {
                                                                                           mOutFileName = outFileName;
                                                                                       }

                                                                                       void IImageSavingCallback.ImageSaving(ImageSavingArgs args)
                                                                                       {
                                                                                           string imageFileName = $"{mOutFileName} shape {++mCount}, of type {args.CurrentShape.ShapeType}{Path.GetExtension(args.ImageFileName)}";

                                                                                           args.ImageFileName = imageFileName;
                                                                                           args.ImageStream = new FileStream(ArtifactsDir + imageFileName, FileMode.Create);

                                                                                           Assert.That(args.ImageStream.CanWrite, Is.True);
                                                                                           Assert.That(args.IsImageAvailable, Is.True);
                                                                                           Assert.That(args.KeepImageStreamOpen, Is.False);
                                                                                       }

                                                                                       private int mCount;
                                                                                       private readonly string mOutFileName;
                                                                                   }

TableContentAlignment

Gets or sets a value that specifies how to align contents in tables when exporting into the Aspose.Words.SaveFormat.Markdown format. The default value is Aspose.Words.Saving.TableContentAlignment.Auto.

public TableContentAlignment TableContentAlignment { get; set; }

Property Value

TableContentAlignment

Examples

Shows how to align contents in tables.

DocumentBuilder builder = new DocumentBuilder();

                                                 builder.InsertCell();
                                                 builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
                                                 builder.Write("Cell1");
                                                 builder.InsertCell();
                                                 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
                                                 builder.Write("Cell2");

                                                 MarkdownSaveOptions saveOptions = new MarkdownSaveOptions { TableContentAlignment = tableContentAlignment };

                                                 builder.Document.Save(ArtifactsDir + "MarkdownSaveOptions.MarkdownDocumentTableContentAlignment.md", saveOptions);

                                                 Document doc = new Document(ArtifactsDir + "MarkdownSaveOptions.MarkdownDocumentTableContentAlignment.md");
                                                 Table table = doc.FirstSection.Body.Tables[0];

                                                 switch (tableContentAlignment)
                                                 {
                                                     case TableContentAlignment.Auto:
                                                         Assert.That(table.FirstRow.Cells[0].FirstParagraph.ParagraphFormat.Alignment, Is.EqualTo(ParagraphAlignment.Right));
                                                         Assert.That(table.FirstRow.Cells[1].FirstParagraph.ParagraphFormat.Alignment, Is.EqualTo(ParagraphAlignment.Center));
                                                         break;
                                                     case TableContentAlignment.Left:
                                                         Assert.That(table.FirstRow.Cells[0].FirstParagraph.ParagraphFormat.Alignment, Is.EqualTo(ParagraphAlignment.Left));
                                                         Assert.That(table.FirstRow.Cells[1].FirstParagraph.ParagraphFormat.Alignment, Is.EqualTo(ParagraphAlignment.Left));
                                                         break;
                                                     case TableContentAlignment.Center:
                                                         Assert.That(table.FirstRow.Cells[0].FirstParagraph.ParagraphFormat.Alignment, Is.EqualTo(ParagraphAlignment.Center));
                                                         Assert.That(table.FirstRow.Cells[1].FirstParagraph.ParagraphFormat.Alignment, Is.EqualTo(ParagraphAlignment.Center));
                                                         break;
                                                     case TableContentAlignment.Right:
                                                         Assert.That(table.FirstRow.Cells[0].FirstParagraph.ParagraphFormat.Alignment, Is.EqualTo(ParagraphAlignment.Right));
                                                         Assert.That(table.FirstRow.Cells[1].FirstParagraph.ParagraphFormat.Alignment, Is.EqualTo(ParagraphAlignment.Right));
                                                         break;
                                                 }
 English