Md2Word.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using GrapeCity.Documents.Word;
  11. using DsWordWeb.Demos.MarkdownToWordRenderer;
  12.  
  13. namespace DsWordWeb.Demos
  14. {
  15. // This example shows how to convert markdown (.md) documents
  16. // to MS Word DOCX and PDF formats.
  17. //
  18. // The conversion is done by the DsWordWeb.Demos.MarkdownToWordRenderer.WordRenderer
  19. // class that uses the Markdig package written by Alexandre Mutel
  20. //to parse markdown, and the DsWord OM to create MS Word documents from it.
  21. //
  22. // The WordRenderer C# source code is included in this sample, to view it
  23. // download the sample zip. The MarkdownToWordRenderer sources are located
  24. // in the Samples/Markdown/Renderer subdirectory of the sample zip.
  25. public class Md2Word
  26. {
  27. public GcWordDocument CreateDocx(string[] sampleParams)
  28. {
  29. var fn = Path.Combine(sampleParams[3].Split('/'));
  30. var markdown = File.ReadAllText(fn);
  31. return WordRenderer.ToWord(markdown);
  32. }
  33.  
  34. public GcWordDocument CreateDocx(int parsIdx = 0)
  35. {
  36. return CreateDocx(GetSampleParamsList()[parsIdx]);
  37. }
  38.  
  39. // Mandatory: name, description, info.
  40. // Custom: .md file.
  41. static readonly List<string[]> s_paramsList = new List<string[]>()
  42. {
  43. new string[] { "@md/DsPdfViewer README.md", "Convert the README.md file shipped with DsPdfViewer", null,
  44. "Resources/Markdown/DsPdfViewer-README.md" },
  45. new string[] { "@md/DsPdfViewer CHANGELOG.md", "Convert the CHANGELOG.md file shipped with DsPdfViewer", null,
  46. "Resources/Markdown/DsPdfViewer-CHANGELOG.md" },
  47. new string[] { "@md/spec.md", "Convert the Markdown specification spec.md file", null,
  48. "Resources/Markdown/spec.md" },
  49. };
  50.  
  51. public static List<string[]> GetSampleParamsList() => s_paramsList;
  52. }
  53. }
  54.