public static IMarkdownEngine GetEngine(ConvertibleDocument document) { switch (document.MarkdownEngine) { case MarkdownEngine.Sundown: return new SundownEngine(); case MarkdownEngine.MarkdownSharp: return new MarkdownSharpEngine(); } return null; }
public void Convert(ConvertibleDocument document, ConversionMetadata conversionMetadata) { if (string.IsNullOrEmpty(conversionMetadata.OutputPath)) { conversionMetadata.OutputPath = document.BasePath; } if (Path.GetFullPath(Path.GetDirectoryName(document.AbsolutePath)) != Path.GetFullPath(conversionMetadata.OutputPath)) { this.CopySourceContent(document.AbsolutePath, conversionMetadata.OutputPath); } if (!string.IsNullOrEmpty(conversionMetadata.MarkdownTemplatePath) && Path.GetFullPath(conversionMetadata.MarkdownTemplatePath) != Path.GetFullPath(conversionMetadata.OutputPath)) { this.CopyTemplateContent(conversionMetadata.MarkdownTemplatePath, conversionMetadata.OutputPath); } this.Render(document, conversionMetadata); ProgressNotificationHelper.Stop(); }
private string Render(ConvertibleDocument document, ConversionMetadata conversionMetadata) { var engine = MarkdownEngineFactory.GetEngine(document); var fileName = Path.GetFileName(Path.ChangeExtension(document.AbsolutePath, "html")); string markdownContent; using (var stream = File.Open(document.AbsolutePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { var reader = new StreamReader(stream, detectEncodingFromByteOrderMarks: true); markdownContent = reader.ReadToEnd(); } var outputContent = engine.Transform(markdownContent); outputContent = this.ProcessHeaders(outputContent); outputContent = this.RemoveCodeSnippetExtraBreakline(outputContent); outputContent = this.PrcessCodeSnippetHeaders(outputContent); if (conversionMetadata.CodeSnippetsHighlighting) { outputContent = new CodeSnippetHighlighter(outputContent).Highlight(); } document.Topics.Clear(); document.Topics.Add(new DocumentTopic { Content = outputContent }); if (!string.IsNullOrEmpty(conversionMetadata.MarkdownTemplatePath)) { var props = new Dictionary<string, object>(); props.Add("Document", document); props.Add("Content", conversionMetadata.Content); props.Add("Package", conversionMetadata.Package); outputContent = TextTemplatingHelper.Process(conversionMetadata.MarkdownTemplatePath, props); } string outputPath = Path.Combine(conversionMetadata.OutputPath, fileName); File.WriteAllText(outputPath, outputContent, System.Text.Encoding.UTF8); ProgressNotificationHelper.Clear(); return outputPath; }