private static void ConvertMarkdownToHtml(CliOptions options) { var markdownMarkup = File.ReadAllText(options.InputFilename); MarkdownToHtmlRenderer markdownToHtmlRenderer = GetRenderer(options); var htmlMarkup = markdownToHtmlRenderer.Render(markdownMarkup); WriteResult(options, htmlMarkup); }
private static INodeRenderer GetNodeRenderer(CliOptions options) { NodeToHtmlEntityConverter converter; if (options.InjectCssClass != null) { converter = new NodeToHtmlEntityConverter(new HtmlAttribute("class", options.InjectCssClass)); } else { converter = new NodeToHtmlEntityConverter(); } return(new NodeHtmlRenderer(new HtmlRenderContext(converter))); }
private static void WriteResult(CliOptions options, string htmlMarkup) { if (options.HtmlFilename == null) { File.WriteAllText(options.OutputFilename, htmlMarkup); } else { // CR (krait): А стрим кто закрывать будет? var templateDom = new HtmlParser().Parse(File.OpenRead(options.HtmlFilename)); templateDom.QuerySelector(options.InjectedHtmlElement).InnerHtml = htmlMarkup; File.WriteAllText(options.OutputFilename, templateDom.DocumentElement.OuterHtml); } }
private static MarkdownToHtmlRenderer GetRenderer(CliOptions options) { var nodeRenderer = GetNodeRenderer(options); var htmlRenderer = new MarkdownToHtmlRenderer( new MarkdownParser(), new MarkdownTokenizerFactory(), nodeRenderer ); if (options.BaseUrl != null) { htmlRenderer = htmlRenderer.WithModificators(new TransformTreeVisitor(new BaseUrlTransformer(options.BaseUrl))); } return(htmlRenderer); }