/// <summary> /// Parses the markdown for a title, renders to HTML and returns a model that /// contains the relevant items. /// </summary> /// <param name="markdown"></param> /// <param name="model"></param> /// <returns></returns> private MarkdownModel ParseMarkdownToModel(string markdown, MarkdownModel model = null) { if (model == null) { model = new MarkdownModel(); } var firstLines = MarkdownUtils.GetLines(markdown, 30); var firstLinesText = String.Join("\n", firstLines); // Assume YAML if (markdown.StartsWith("---")) { var yaml = MarkdownUtils.ExtractString(firstLinesText, "---", "---", returnDelimiters: true); if (yaml != null) { model.Title = MarkdownUtils.ExtractString(yaml, "title: ", "\n"); model.YamlHeader = yaml.Replace("---", "").Trim(); } } if (model.Title == null) { foreach (var line in firstLines.Take(10)) { if (line.TrimStart().StartsWith("# ")) { model.Title = line.TrimStart(new char[] { ' ', '\t', '#' }); break; } } } model.RawMarkdown = markdown; model.RenderedMarkdown = Markdown.ParseHtmlString(markdown, sanitizeHtml: Configuration.SanitizeHtml); model.PhysicalPath = HttpContext.Current.Request.PhysicalPath; model.RelativePath = HttpContext.Current.Request.Path; return(model); }
protected override void OnInit(EventArgs e) { base.OnInit(e); MarkdownModel = Context.Items[MarkdownHttpHandler.ModelKey] as MarkdownModel; }