This article explains how to merge MD files in C#. It has details to set the IDE, a list of steps, and a sample code to merge Markdown files in C# with the help of a few API calls only. You will learn to utilize the MarkdownLoadOptions object to customize the loading of an MD file.
Steps to Merge MD in C#
- Set the IDE to use Aspose.Words for .NET to merge multiple MD files
- Import the necessary classes and modules from the library
- Load the first MD file into the Document object and set the callback function for handling errors and warnings
- Load the second MD file into another Document object with the same configuration as above
- Call the AppendDocument() method from one document and pass the other MD file with import format mode
- Save the document that called the AppendDocument() as it contains the contents of the other MD file
These steps summarize the process to merge Markdown in C#. Import the necessary namespaces and classes, load both the source MD files into the individual Document objects, set the warning callback function, and use the destination Document object for calling the AppendDocument() by passing the MD file whose contents are to be appended, and set the ImportFormatMode as well. Repeat the process by appending more MD files if loaded, and save the resultant destination MD file on the disk.
Code to Combine MD in C#
The above sample code has demonstrated the process to merge Markdown files. You can set the PreserveEmptyLines flag to preserve blank/empty lines while loading an MD file, the flag to import underlined text, and define the character to represent a soft line break. The ImportFormatMode enum can be used to specify the merging format i.e. use destination style, source style, or maintain different formatting as it is.
This short tutorial has taught us how to merge multiple MD files. To convert an MD file to a Word file, refer to the article Convert Markdown to Word using C#.