private void GenerateSearchContents(RuntimeSettings settings, ILog log) { _buffer.WriteElement(HtmlElement.Div, "searchcontents", "nodisplay"); using var pipeline = new BookGenPipeline(BookGenPipeline.Plain); foreach (var chapter in settings.TocContents.Chapters) { foreach (var link in settings.TocContents.GetLinksForChapter(chapter)) { log.Detail("Processing file for search index: {0}", link.Url); var fileContent = settings.SourceDirectory.Combine(link.Url).ReadFile(log); var rendered = pipeline.RenderMarkdown(fileContent); var file = Path.ChangeExtension(link.Url, ".html"); var fullpath = $"{settings.Configuration.HostName}{file}"; _buffer.AppendFormat("<div title=\"{0}\" data-link=\"{1}\">", link.Text, fullpath); _buffer.Append(_spaces.Replace(rendered, " ")); _buffer.Append("</div>\n"); } } _buffer.CloseElement(HtmlElement.Div); }
public void RunStep(RuntimeSettings settings, ILog log) { if (Content == null) { throw new DependencyException(nameof(Content)); } if (Template == null) { throw new DependencyException(nameof(Template)); } log.Info("Generating Index file..."); var input = settings.SourceDirectory.Combine(settings.Configuration.Index); FsPath?target = settings.OutputDirectory.Combine("index.html"); using (var pipeline = new BookGenPipeline(BookGenPipeline.Web)) { pipeline.InjectRuntimeConfig(settings); Content.Content = pipeline.RenderMarkdown(input.ReadFile(log)); } var html = Template.Render(); target.WriteFile(log, html); }
private static string GetDescription(ILog log, FsPath file) { using (var pipeline = new BookGenPipeline(BookGenPipeline.Plain)) { string?content = file.ReadFile(log).Replace('\n', ' ').Trim(); string?description = pipeline.RenderMarkdown(content); var limit = description.Length < 190 ? description.Length : 190; return(description.Substring(0, limit) + "..."); } }
public void RunStep(RuntimeSettings settings, ILog log) { if (Content == null) { throw new DependencyException(nameof(Content)); } if (Template == null) { throw new DependencyException(nameof(Template)); } log.Info("Generating Sub Markdown Files..."); using var pipeline = new BookGenPipeline(BookGenPipeline.Web); pipeline.InjectRuntimeConfig(settings); var bag = new ConcurrentBag <(string source, FsPath target, string title, string content)>(); Parallel.ForEach(settings.TocContents.Files, file => { (string source, FsPath target, string title, string content)result; var input = settings.SourceDirectory.Combine(file); result.target = settings.OutputDirectory.Combine(Path.ChangeExtension(file, ".html")); log.Detail("Processing file: {0}", input); var inputContent = input.ReadFile(log); result.title = MarkdownUtils.GetTitle(inputContent); if (string.IsNullOrEmpty(result.title)) { log.Warning("No title found in document: {0}", file); result.title = file; } result.source = file; result.content = pipeline.RenderMarkdown(inputContent); bag.Add(result); }); log.Info("Writing files to disk..."); foreach (var item in bag) { Content.Title = item.title; Content.Metadata = settings.MetataCache[item.source]; Content.Content = item.content; item.target.WriteFile(log, Template.Render()); } }
public override bool Execute(string[] arguments) { Md2HtmlParameters args = new Md2HtmlParameters(); if (!ArgumentParser.ParseArguments(arguments, args)) { return(false); } var log = new ConsoleLog(LogLevel.Info); string md = args.InputFile.ReadFile(log); string pageTemplate = ResourceHandler.GetFile(KnownFile.TemplateSinglePageHtml); string cssForInline = ""; if (args.Css.IsExisting) { cssForInline = args.Css.ReadFile(log); } using var pipeline = new BookGenPipeline(BookGenPipeline.Preview); pipeline.InjectPath(args.InputFile.GetDirectory()); pipeline.SetSyntaxHighlightTo(!args.NoSyntax); var mdcontent = pipeline.RenderMarkdown(md); string rendered; if (args.RawHtml) { rendered = mdcontent; } else { rendered = pageTemplate.Replace("<!--{css}-->", cssForInline); rendered = rendered.Replace("<!--{content}-->", mdcontent); } if (args.OutputFile == new FsPath("con")) { Console.WriteLine(rendered); } else { args.OutputFile.WriteFile(log, rendered); } return(true); }
public void RunStep(RuntimeSettings settings, ILog log) { if (Content == null) { throw new DependencyException(nameof(Content)); } if (Template == null) { throw new DependencyException(nameof(Template)); } log.Info("Generating Printable html..."); FsPath?target = settings.OutputDirectory.Combine("print.html"); StringBuilder buffer = new StringBuilder(); using var pipeline = new BookGenPipeline(BookGenPipeline.Print); pipeline.InjectRuntimeConfig(settings); foreach (var chapter in settings.TocContents.Chapters) { log.Info("Processing: {0}...", chapter); buffer.AppendFormat("<h1>{0}</h1>\r\n\r\n", chapter); foreach (var file in settings.TocContents.GetLinksForChapter(chapter).Select(l => l.Url)) { log.Detail("Processing file for print output: {0}", file); var input = settings.SourceDirectory.Combine(file); var inputContent = input.ReadFile(log); var rendered = pipeline.RenderMarkdown(inputContent); buffer.AppendLine(rendered); buffer.AppendLine(NewPage); } } Content.Content = buffer.ToString(); target.WriteFile(log, Template.Render()); }
private void Preview(HttpListenerRequest request, HttpListenerResponse response) { Dictionary <string, string> parameters = request.ParsePostParameters(); if (parameters.ContainsKey("content")) { string base64content = Uri.UnescapeDataString(parameters["content"]); byte[] contentBytes = Convert.FromBase64String(base64content); string rawContent = Encoding.UTF8.GetString(contentBytes); using (var pipeline = new BookGenPipeline(BookGenPipeline.Preview)) { pipeline.InjectPath(new FsPath(_workdir)); string rendered = pipeline.RenderMarkdown(rawContent); response.WriteString(rendered, "text/html"); } } }
public void RunStep(RuntimeSettings settings, ILog log) { if (Content == null) { throw new DependencyException(nameof(Content)); } if (Template == null) { throw new DependencyException(nameof(Template)); } log.Info("Generating index files for sub content folders..."); using var pipeline = new BookGenPipeline(BookGenPipeline.Web); pipeline.InjectRuntimeConfig(settings); foreach (var file in settings.TocContents.Files) { var dir = Path.GetDirectoryName(file); if (dir == null) { continue; } FsPath?target = settings.OutputDirectory.Combine(dir).Combine("index.html"); if (!target.IsExisting) { var mdcontent = CreateContentLinks(settings, dir); Content.Title = dir; Content.Content = pipeline.RenderMarkdown(mdcontent); Content.Metadata = ""; var html = Template.Render(); log.Detail("Creating file: {0}", target); target.WriteFile(log, html); } } }
public void RunStep(RuntimeSettings settings, ILog log) { if (Content == null) { throw new DependencyException(nameof(Content)); } if (Template == null) { throw new DependencyException(nameof(Template)); } log.Info("Generating epub pages..."); int index = 1; using var pipeline = new BookGenPipeline(BookGenPipeline.Epub); pipeline.InjectRuntimeConfig(settings); foreach (var file in settings.TocContents.Files) { _session.GeneratedFiles.Add($"page_{index:D3}"); FsPath?target = settings.OutputDirectory.Combine($"epubtemp\\OPS\\page_{index:D3}.xhtml"); log.Detail("Processing file for epub output: {0}", file); var input = settings.SourceDirectory.Combine(file); var inputContent = input.ReadFile(log); Content.Title = MarkdownUtils.GetTitle(inputContent); Content.Content = pipeline.RenderMarkdown(inputContent); var html = XhtmlNormalizer.NormalizeToXHTML(Template.Render()); target.WriteFile(log, html); ++index; } }
public void RunStep(RuntimeSettings settings, ILog log) { if (Content == null) { throw new DependencyException(nameof(Content)); } if (Template == null) { throw new DependencyException(nameof(Template)); } log.Info("Generating Wordpress export content..."); _session.CurrentChannel.Item = new List <Item>(); var host = settings.CurrentBuildConfig.TemplateOptions[TemplateOptions.WordpressTargetHost]; bool parentpageCreate = settings.CurrentBuildConfig.TemplateOptions.TryGetOption(TemplateOptions.WordpressCreateParent, out bool createparent) && createparent; bool createfillers = settings.CurrentBuildConfig.TemplateOptions.TryGetOption(TemplateOptions.WordpressCreateFillerPages, out bool filler) && filler; int mainorder = 0; int uid = 2000; int globalparent = 0; if (parentpageCreate) { string fillerPage = createfillers ? CreateFillerPage(settings.TocContents.GetLinksForChapter()) : ""; string title = settings.CurrentBuildConfig.TemplateOptions[TemplateOptions.WordpresCreateParentTitle]; string path = $"{host}{Encode(title)}"; Item parent = CreateItem(uid, 0, mainorder, fillerPage, title, path, settings.CurrentBuildConfig.TemplateOptions); _session.CurrentChannel.Item.Add(parent); globalparent = uid; ++uid; } using var pipeline = new BookGenPipeline(BookGenPipeline.Wordpress); pipeline.InjectRuntimeConfig(settings); foreach (var chapter in settings.TocContents.Chapters) { string fillerPage = createfillers ? CreateFillerPage(settings.TocContents.GetLinksForChapter(chapter)) : ""; string path = $"{host}{Encode(chapter)}"; int parent_uid = uid; Item parent = CreateItem(uid, globalparent, mainorder, fillerPage, chapter, path, settings.CurrentBuildConfig.TemplateOptions); _session.CurrentChannel.Item.Add(parent); int suborder = 0; uid++; foreach (var file in settings.TocContents.GetLinksForChapter(chapter).Select(l => l.Url)) { log.Detail("Processing {0}...", file); var input = settings.SourceDirectory.Combine(file); var raw = input.ReadFile(log); Content.Content = pipeline.RenderMarkdown(raw); var title = MarkdownUtils.GetTitle(raw); string subpath = $"{host}{Encode(chapter)}/{Encode(title)}"; var result = CreateItem(uid, parent_uid, suborder, Template.Render(), title, subpath, settings.CurrentBuildConfig.TemplateOptions); _session.CurrentChannel.Item.Add(result); ++suborder; ++uid; } ++mainorder; } }