Md2Word.cs
//
// This code is part of GrapeCity Documents for Word samples.
// Copyright (c) GrapeCity, Inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using GrapeCity.Documents.Word;
using GcWordWeb.Samples.MarkdownToWordRenderer;

namespace GcWordWeb.Samples
{
    // This example shows how to convert markdown (.md) documents
    // to MS Word DOCX and PDF formats.
    //
    // The conversion is done by the GcWordWeb.Samples.MarkdownToWordRenderer.WordRenderer
    // class that uses the Markdig package written by Alexandre Mutel
    //to parse markdown, and the GcWord OM to create MS Word documents from it.
    //
    // The WordRenderer C# source code is included in this sample, to view it
    // download the sample zip. The MarkdownToWordRenderer sources are located
    // in the Samples/Markdown/Renderer subdirectory of the sample zip.
    public class Md2Word
    {
        public GcWordDocument CreateDocx(string[] sampleParams)
        {
            var fn = Path.Combine(sampleParams[3].Split('/'));
            var markdown = File.ReadAllText(fn);
            return WordRenderer.ToWord(markdown);
        }

        public GcWordDocument CreateDocx(int parsIdx = 0)
        {
            return CreateDocx(GetSampleParamsList()[parsIdx]);
        }

        // Mandatory: name, description, info.
        // Custom: .md file.
        static readonly List<string[]> s_paramsList = new List<string[]>()
            {
                new string[] { "@md/GcPdfViewer README.md", "Convert the README.md file shipped with GcPdfViewer", null,
                    "Resources/Markdown/GcPdfViewer-README.md" },
                new string[] { "@md/GcPdfViewer CHANGELOG.md", "Convert the CHANGELOG.md file shipped with GcPdfViewer", null,
                    "Resources/Markdown/GcPdfViewer-CHANGELOG.md" },
                new string[] { "@md/spec.md", "Convert the Markdown specification spec.md file", null,
                    "Resources/Markdown/spec.md" },
            };

        public static List<string[]> GetSampleParamsList() => s_paramsList;
    }
}