private SyndicationFeed GenerateFeed() { var currentBlog = this.CurrentBlog; var md = new MarkdownDeep.Markdown(); List <SyndicationItem> posts = new List <SyndicationItem>(); foreach (var post in _postRepository.FeedPosts(currentBlog.Id).OrderByDescending(p => p.Posted).Take(25).AsEnumerable()) { var item = new SyndicationItem(post.Title, post.Body, new Uri(currentBlog.AuthoritiveUrl.TrimEnd('/') + "/" + post.Path.TrimStart('/'))); item.Title = new TextSyndicationContent(post.Title); item.Content = new TextSyndicationContent(md.Transform(post.Body), TextSyndicationContentKind.Html); item.PublishDate = new DateTimeOffset(post.Posted); item.LastUpdatedTime = new DateTimeOffset(post.Posted); item.Id = post.PostGuid.ToString(); posts.Add(item); } return(new SyndicationFeed("StaticVoid", "A blog on .Net", new Uri(currentBlog.AuthoritiveUrl), posts) { Language = "en-US", LastUpdatedTime = posts.Any() ? posts.Max(p => p.LastUpdatedTime) : new DateTime(2012, 12, 21), Id = currentBlog.BlogGuid.ToString() }); }
public static void RunTestJS(string input, bool SafeMode, bool ExtraMode, bool MarkdownInHtml, bool AutoHeadingIDs) { string normalized_input = input.Replace("\r\n", "\n").Replace("\r", "\n"); // Work out the expected output using C# implementation var md = new MarkdownDeep.Markdown(); md.SafeMode = SafeMode; md.ExtraMode = ExtraMode; md.MarkdownInHtml = MarkdownInHtml; md.AutoHeadingIDs = AutoHeadingIDs; string expected = md.Transform(normalized_input); // Transform using javascript implementation string actual = TransformUsingJS(input, SafeMode, ExtraMode, MarkdownInHtml, AutoHeadingIDs); actual = actual.Replace("\r", ""); expected = expected.Replace("\r", ""); string sep = new string('-', 30) + "\n"; Console.WriteLine("Input:\n" + sep + input); Console.WriteLine("Actual:\n" + sep + actual); Console.WriteLine("Expected:\n" + sep + expected); // Check it Assert.AreEqual(expected, actual); }
public static string FromMarkdown(this HtmlHelper helper, string markdown) { var md = new MarkdownDeep.Markdown(); md.SafeMode = true; md.ExtraMode = true; return md.Transform(markdown); }
private static void ContentService_Saving(IContentService sender, SaveEventArgs <IContent> e) { if (UmbracoConfig.For.ArticulateOptions().AutoGenerateExcerpt) { foreach (var c in e.SavedEntities .Where(c => c.ContentType.Alias.InvariantEquals("ArticulateRichText") || c.ContentType.Alias.InvariantEquals("ArticulateMarkdown"))) { //fill in the excerpt if it is empty if (c.GetValue <string>("excerpt").IsNullOrWhiteSpace()) { if (c.HasProperty("richText")) { var val = c.GetValue <string>("richText"); c.SetValue("excerpt", UmbracoConfig.For.ArticulateOptions().GenerateExcerpt(val)); } else { var val = c.GetValue <string>("markdown"); var md = new MarkdownDeep.Markdown(); val = md.Transform(val); c.SetValue("excerpt", UmbracoConfig.For.ArticulateOptions().GenerateExcerpt(val)); } } //now fill in the social description if it is empty with the excerpt if (c.GetValue <string>("socialDescription").IsNullOrWhiteSpace()) { c.SetValue("socialDescription", c.GetValue <string>("excerpt")); } } } }
private void renderPage(object sender, System.Timers.ElapsedEventArgs e) { DateTime lastWrite = File.GetLastWriteTime(fileName); if (lastWrite != latestWrite) { latestWrite = lastWrite; var md = new MarkdownDeep.Markdown(); md.SafeMode = false; TextReader infile = new StreamReader(fileName); String input = infile.ReadToEnd(); infile.Close(); String output; if (jekyllMode) { output = md.Transform(Regex.Replace(input, @"---[\p{IsBasicLatin}]+---\r", "")); } else { output = md.Transform(input); } webTargetPage.DocumentText = output; } }
public void PreviewForUnpublishedPostTest() { IRepository<Post> postRepo = new SimpleRepository<Post>(new InMemoryRepositoryDataSource<Post>(new List<Post> { new Post { Status = PostStatus.Published, Path ="2013/04/10/some-other-post", Posted = new DateTime(2013,4,10), Author = new User{ Email = "" }, BlogId = 1 }, new Post { Id = 1, Status = PostStatus.Unpublished, Path ="2013/04/14/some-post", Posted = new DateTime(2013,4,14), Author = new User{ Email = "", FirstName = "Joe", LastName = "Bloggs" }, DraftBody = "asdf", DraftTitle = "qwerty", BlogId = 1 } })); PostController sut = new PostController(postRepo, null, _blogRepo, _mockHttpContext.Object); var result = (ViewResult)sut.Preview(1); Assert.IsNotNull(result); var model = result.Model as PostModel; Assert.IsNotNull(model); var md = new MarkdownDeep.Markdown(); Assert.AreEqual("Joe Bloggs", model.Author.Name); Assert.AreEqual(md.Transform("asdf"), model.Body); Assert.AreEqual("qwerty", model.Title); }
// // GET: /Project/Feedback/projectid // // Updated to v2.0 w/ audit trails public ActionResult ViewFeedback(int projectid = 0) { Mapper.CreateMap<ProjectVersion, ProjectView>(); Mapper.CreateMap<Project, ProjectView>(); Project project = db.Projects.Find(projectid); ProjectView feedbackProject = Mapper.Map<Project, ProjectView>(project); Mapper.Map(project.CurrentVersion, feedbackProject); feedbackProject.Feedbacks = db.Feedbacks.Where(b => b.owner.ProjectId.Equals(projectid)).ToList(); //takes the comment and turns it into markedup html var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.SafeMode = false; foreach (var feedback in feedbackProject.Feedbacks) { string MarkedUp = md.Transform(feedback.Comment); feedback.Comment = MarkedUp; } return View(feedbackProject); }
private void SetMessage(string text) { var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.SafeMode = false; ViewBag.Message = md.Transform(text); }
void ContentService_Saving(IContentService sender, SaveEventArgs <Umbraco.Core.Models.IContent> e) { foreach (var c in e.SavedEntities) { //fill in the excerpt if required if (c.ContentType.Alias.InvariantEquals("ArticulateRichText") || c.ContentType.Alias.InvariantEquals("ArticulateMarkdown")) { if (c.GetValue <string>("excerpt").IsNullOrWhiteSpace()) { if (c.HasProperty("richText")) { var val = c.GetValue <string>("richText"); c.SetValue("excerpt", val == null ? string.Empty : string.Join("", val.StripHtml().StripNewLines().Take(200))); } else { var val = c.GetValue <string>("markdown"); var md = new MarkdownDeep.Markdown(); val = md.Transform(val); c.SetValue("excerpt", val == null ? string.Empty : string.Join("", val.StripHtml().StripNewLines().Take(200))); } } } } }
public static void RunResourceTest(string resourceName) { string input = Utils.LoadTextResource(resourceName); string expected = Utils.LoadTextResource(System.IO.Path.ChangeExtension(resourceName, "html")); var md = new MarkdownDeep.Markdown(); md.SafeMode = resourceName.IndexOf("(SafeMode)") >= 0; md.ExtraMode = resourceName.IndexOf("(ExtraMode)") >= 0; md.GitHubCodeBlocks = resourceName.IndexOf("(GitHubMode)") >= 0; md.DocNetMode = resourceName.IndexOf("(DocNetMode") >= 0; md.ConvertLocalLinks = resourceName.IndexOf("(ConvertLocalLinks") >= 0; md.MarkdownInHtml = resourceName.IndexOf("(MarkdownInHtml)") >= 0; md.AutoHeadingIDs = resourceName.IndexOf("(AutoHeadingIDs)") >= 0; if (resourceName.IndexOf("(Titled)") >= 0) { md.HtmlClassTitledImages = "figure"; } if (md.DocNetMode) { md.GitHubCodeBlocks = true; } string actual = md.Transform(input); string actual_clean = Utils.strip_redundant_whitespace(actual); string expected_clean = Utils.strip_redundant_whitespace(expected); string sep = new string('-', 30) + "\n"; Console.WriteLine("Input:\n" + sep + input); Console.WriteLine("Actual:\n" + sep + actual); Console.WriteLine("Expected:\n" + sep + expected); Assert.AreEqual(expected_clean, actual_clean); }
public static void RunTestJS(string input, bool SafeMode, bool ExtraMode, bool MarkdownInHtml, bool AutoHeadingIDs) { string normalized_input = input.Replace("\r\n", "\n").Replace("\r", "\n"); // Work out the expected output using C# implementation var md = new MarkdownDeep.Markdown(); md.SafeMode = SafeMode; md.ExtraMode = ExtraMode; md.MarkdownInHtml = MarkdownInHtml; md.AutoHeadingIDs = AutoHeadingIDs; string expected = md.Transform(normalized_input); // Transform using javascript implementation string actual = TransformUsingJS(input, SafeMode, ExtraMode, MarkdownInHtml, AutoHeadingIDs); actual = actual.Replace("\r", ""); expected = expected.Replace("\r", ""); string sep = new string('-', 30) + "\n"; Console.WriteLine("Input:\n" + sep + input); Console.WriteLine("Actual:\n" + sep + actual); Console.WriteLine("Expected:\n" + sep + expected); // Check it Assert.AreEqual(expected, actual); }
public void Linkify(string text, Action<string> onSuccess) { text = Regex.Replace(text, @"(http\://|https\://|www.)\S*", match => { if (match.Index != 0) { var previousChar = text[match.Index - 1]; if (!char.IsWhiteSpace(previousChar)) return match.Value; } var value = match.Value; var path = new UriBuilder(value).Uri.AbsolutePath; if (match.Groups[1].Value == "www.") value = "http://" + value; return path.EndsWith("jpg") || path.EndsWith("gif") || path.EndsWith("png") ? "![Inline Image](" + value + ")" : "[" + value + "](" + value + ")"; }); text = new MarkdownDeep.Markdown { ExtraMode = true, NewWindowForExternalLinks = true, NewWindowForLocalLinks = true, }.Transform(text); text = text.Replace("\n", ""); text = text.Replace(@"\", @"\\"); onSuccess(text); }
public static void RunResourceTest(string resourceName) { string input = Utils.LoadTextResource(resourceName); string expected = Utils.LoadTextResource(System.IO.Path.ChangeExtension(resourceName, "html")); var md = new MarkdownDeep.Markdown(); md.SafeMode = resourceName.IndexOf("(SafeMode)") >= 0; md.ExtraMode = resourceName.IndexOf("(ExtraMode)") >= 0; md.GitHubCodeBlocks = resourceName.IndexOf("(GitHubMode)") >= 0; md.DocNetMode = resourceName.IndexOf("(DocNetMode") >= 0; md.MarkdownInHtml = resourceName.IndexOf("(MarkdownInHtml)") >= 0; md.AutoHeadingIDs = resourceName.IndexOf("(AutoHeadingIDs)") >= 0; if(resourceName.IndexOf("(Titled)") >= 0) { md.HtmlClassTitledImages = "figure"; } if(md.DocNetMode) { md.GitHubCodeBlocks = true; } string actual = md.Transform(input); string actual_clean = Utils.strip_redundant_whitespace(actual); string expected_clean = Utils.strip_redundant_whitespace(expected); string sep = new string('-', 30) + "\n"; Console.WriteLine("Input:\n" + sep + input); Console.WriteLine("Actual:\n" + sep + actual); Console.WriteLine("Expected:\n" + sep + expected); Assert.AreEqual(expected_clean, actual_clean); }
private void renderPage(object sender, System.Timers.ElapsedEventArgs e) { DateTime lastWrite = File.GetLastWriteTime(fileName); if (lastWrite != latestWrite) { latestWrite = lastWrite; var md = new MarkdownDeep.Markdown(); md.SafeMode = false; TextReader infile = new StreamReader(fileName); String input = infile.ReadToEnd(); infile.Close(); String output; if (jekyllMode) { output = md.Transform(Regex.Replace(input, @"---[\p{IsBasicLatin}]+---\r", "")); } else { output = md.Transform(input); } webTargetPage.DocumentText = output; } }
private void AddBlogPosts(IContent archiveNode, BlogMLDocument blogMlDoc, string tagGroup) { const int pageSize = 1000; var pageIndex = 0; IContent[] posts; do { long total; posts = _applicationContext.Services.ContentService.GetPagedChildren(archiveNode.Id, pageIndex, pageSize, out total, "createDate").ToArray(); foreach (var child in posts) { string content = ""; if (child.ContentType.Alias.InvariantEquals("ArticulateRichText")) { //TODO: this would also need to export all macros content = child.GetValue <string>("richText"); } else if (child.ContentType.Alias.InvariantEquals("ArticulateMarkdown")) { content = child.GetValue <string>("markdown"); var markdown = new MarkdownDeep.Markdown(); content = markdown.Transform(content); } var blogMlPost = new BlogMLPost() { Id = child.Key.ToString(), Name = new BlogMLTextConstruct(child.Name), Title = new BlogMLTextConstruct(child.Name), ApprovalStatus = BlogMLApprovalStatus.Approved, PostType = BlogMLPostType.Normal, CreatedOn = child.CreateDate, LastModifiedOn = child.UpdateDate, Content = new BlogMLTextConstruct(content, BlogMLContentType.Html), Excerpt = new BlogMLTextConstruct(child.GetValue <string>("excerpt")), Url = new Uri(_umbracoContext.UrlProvider.GetUrl(child.Id), UriKind.RelativeOrAbsolute) }; var author = blogMlDoc.Authors.FirstOrDefault(x => x.Title != null && x.Title.Content.InvariantEquals(child.GetValue <string>("author"))); if (author != null) { blogMlPost.Authors.Add(author.Id); } var categories = _applicationContext.Services.TagService.GetTagsForEntity(child.Id, tagGroup); foreach (var category in categories) { blogMlPost.Categories.Add(category.Id.ToString()); } //TODO: Tags isn't natively supported blogMlDoc.AddPost(blogMlPost); } pageIndex++; } while (posts.Length == pageSize); }
/// <summary> /// Populate the view given the specified text. /// </summary> /// <param name="contents"></param> /// <param name="editingEnabled"></param> /// <returns></returns> private bool PopulateView(string contents, bool editingEnabled) { if (contents.Contains(@"{\rtf")) { richTextBox1.Rtf = contents; } else { var doc = new MigraDoc.DocumentObjectModel.Document(); var section = doc.AddSection(); if (contents.Contains("<html>")) { HtmlToMigraDoc.Convert(contents, section, ImagePath); } else { MarkdownDeep.Markdown markDown = new MarkdownDeep.Markdown(); markDown.ExtraMode = true; string html = markDown.Transform(contents); editingEnabled = true; HtmlToMigraDoc.Convert(html, section, ImagePath); } RtfDocumentRenderer renderer = new RtfDocumentRenderer(); richTextBox1.Rtf = renderer.RenderToString(doc, null); } return(editingEnabled); }
public static void RunResourceTest(string resourceName) { string input = Utils.LoadTextResource(resourceName); string expected = Utils.LoadTextResource(System.IO.Path.ChangeExtension(resourceName, "html")); var md = new MarkdownDeep.Markdown(); md.SafeMode = resourceName.IndexOf("(SafeMode)") >= 0;; md.ExtraMode = resourceName.IndexOf("(ExtraMode)") >= 0;; md.MarkdownInHtml = resourceName.IndexOf("(MarkdownInHtml)") >= 0; md.AutoHeadingIDs = resourceName.IndexOf("(AutoHeadingIDs)") >= 0; md.RespectOrderedListStartValues = resourceName.IndexOf("(OLStart)") >= 0; string actual = md.Transform(input); string actual_clean = Utils.strip_redundant_whitespace(actual); string expected_clean = Utils.strip_redundant_whitespace(expected); string sep = new string('-', 30) + "\n"; Console.WriteLine("Input:\n" + sep + input); Console.WriteLine("Actual:\n" + sep + actual); Console.WriteLine("Expected:\n" + sep + expected); Assert.AreEqual(expected_clean, actual_clean); }
// Split the markdown into sections, one section for each // top level heading public static List <string> SplitSections(string markdown) { // Build blocks var md = new MarkdownDeep.Markdown(); // Process blocks var blocks = md.ProcessBlocks(markdown); // Create sections var Sections = new List <string>(); int iPrevSectionOffset = 0; for (int i = 0; i < blocks.Count; i++) { var b = blocks[i]; if (md.IsSectionHeader(b)) { // Get the offset of the section int iSectionOffset = b.lineStart; // Add section Sections.Add(markdown.Substring(iPrevSectionOffset, iSectionOffset - iPrevSectionOffset)); iPrevSectionOffset = iSectionOffset; } } // Add the last section if (markdown.Length > iPrevSectionOffset) { Sections.Add(markdown.Substring(iPrevSectionOffset)); } return(Sections); }
private SyndicationFeed GenerateFeed() { var currentBlog = this.CurrentBlog; var md = new MarkdownDeep.Markdown(); List<SyndicationItem> posts = new List<SyndicationItem>(); foreach (var post in _postRepository.FeedPosts(currentBlog.Id).OrderByDescending(p => p.Posted).Take(25).AsEnumerable()) { var item = new SyndicationItem(post.Title, post.Body, new Uri(currentBlog.AuthoritiveUrl.TrimEnd('/') + "/" + post.Path.TrimStart('/'))); item.Title = new TextSyndicationContent(post.Title); item.Content = new TextSyndicationContent(md.Transform(post.Body), TextSyndicationContentKind.Html); item.PublishDate = new DateTimeOffset(post.Posted); item.LastUpdatedTime = new DateTimeOffset(post.Posted); item.Id = post.PostGuid.ToString(); posts.Add(item); } return new SyndicationFeed("StaticVoid", "A blog on .Net", new Uri(currentBlog.AuthoritiveUrl), posts) { Language = "en-US", LastUpdatedTime = posts.Any() ? posts.Max(p=>p.LastUpdatedTime) : new DateTime(2012,12,21), Id = currentBlog.BlogGuid.ToString() }; }
public ActionResult Preview(int id) { var currentBlog = CurrentBlog; int blogId = currentBlog.Id; var post = _postRepository.PostsForBlog(currentBlog.Id, p => p.Author).FirstOrDefault(p => p.Id == id); if (post == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var md = new MarkdownDeep.Markdown(); return(View("Post", new PostModel { Body = md.Transform(post.DraftBody), Description = post.DraftDescription, Title = post.DraftTitle, Posted = DateTime.Now, CanonicalUrl = post.Canonical, OtherPosts = new List <PartialPostForLinkModel>(), Author = new PostAuthor { GravatarUrl = post.Author.Email.GravitarUrlFromEmail(), Name = post.Author.FullName(), GooglePlusProfileUrl = post.Author.GooglePlusProfileUrl } })); }
private void PrepareJobSearchView(JobSearch jobSearch) { var md = new MarkdownDeep.Markdown(); ViewBag.JobSearchId = jobSearch.Id; ViewBag.Title = jobSearch.Title; ViewBag.PublicNotes = new MvcHtmlString(md.Transform(jobSearch.PublicNotes)); }
public static string MarkdownTransform(this HtmlHelper html, string paramToTransform) { var markdown = new MarkdownDeep.Markdown(); markdown.SafeMode = false; markdown.ExtraMode = true; return markdown.Transform(paramToTransform); }
public string Transform(string markdown) { var markdownDeep = new MarkdownDeep.Markdown { ExtraMode = true }; return(markdownDeep.Transform(markdown)); }
public void SetUp() { markdown = new MarkdownDeep.Markdown(); message1 = new MessageViewModel { AuthorName = "Dianne", ID = 1, RoomID = 12345, Text = "Test!" }; mockRoomViewModelReader = new Mock<IRoomViewModelReader>(); var roomMessages = new[] { message1 }; mockRoomViewModelReader.Setup(reader => reader.GetRoomMessages(It.IsAny<int>())).Returns(roomMessages); }
public static string FromMarkdown(this HtmlHelper helper, string markdown) { var md = new MarkdownDeep.Markdown(); md.SafeMode = true; md.ExtraMode = true; return(md.Transform(markdown)); }
public static string GetHtmlFromMarkdown(string markdownText) { var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.SafeMode = false; return md.Transform(markdownText); }
private void TextUpdate(object sender, EventArgs e) { MarkdownDeep.Markdown markDown = new MarkdownDeep.Markdown(); markDown.ExtraMode = true; string html = markDown.Transform(memoView1.MemoText); PopulateView(html); }
private static string ParseMarkdown(string markdown) { var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.SafeMode = false; return md.Transform(markdown); }
private void SetMessage(string text) { var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.SafeMode = false; ViewBag.Message = md.Transform(text); }
public static string FormatMessage(String originalMessage) { MarkdownDeep.Markdown m = new MarkdownDeep.Markdown(); m.ExtraMode = true; m.SafeMode = true; return m.Transform(originalMessage); }
public MarkdownConverter() { _markdown = new MarkdownDeep.Markdown { ExtraMode = true, HtmlClassTitledImages = "Figure", FormatCodeBlock = FormatCodeBlock, }; }
public MarkdownConverter() { _markdown = new MarkdownDeep.Markdown { ExtraMode = true, HtmlClassTitledImages = "Figure", FormatCodeBlock = FormatCodeBlock, }; }
public static string GetHtmlFromMarkdown(string markdownText) { var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.SafeMode = false; return(md.Transform(markdownText)); }
private static string ParseMarkdown(string markdown) { var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.SafeMode = false; return(md.Transform(markdown)); }
private void PrepareJobSearchView(JobSearch jobSearch) { var md = new MarkdownDeep.Markdown(); ViewBag.JobSearchId = jobSearch.Id; ViewBag.Title = jobSearch.Title; ViewBag.PublicNotes = new MvcHtmlString(md.Transform(jobSearch.PublicNotes)); ViewBag.TechnicalSkillLevels = TechnicalSkillLevelExtensions.GetValues(); }
public ActionResult Markdown() { var md = new MarkdownDeep.Markdown(); md.SafeMode = true; md.ExtraMode = true; // Transform the content into HTML and pass to the view ViewData["content"] = md.Transform(m_Content); return View(); }
private static void ConvertToHtml(string inputfilename, string outputfilename) { string mdText = File.ReadAllText(inputfilename); var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; string output = md.Transform(mdText); File.WriteAllText(outputfilename, output); }
public static List<PostEntity> GetPagesFromCache(this ICacheService cacheService, IPost postRepository, string keyName, bool isMarkdown) { var markdown = new MarkdownDeep.Markdown{ ExtraMode = true }; var pages = cacheService.Get(keyName, () => postRepository.GetPages()); if (isMarkdown) { pages.ForEach(p => p.PostContent = markdown.Transform(p.PostContent)); } return pages; }
public override void SetValue(object value) { if (value != null) { string html = (string)value; var MarkDownEngine = new MarkdownDeep.Markdown(); html = MarkDownEngine.Transform(html); webView.LoadHtmlString(html, new Foundation.NSUrl("")); } }
public ActionResult Index(DiscussionData data) { Compression.SetCompression(); var code = Model.GetCode(data.Guid, true); if (code == null) { throw new HttpException(404, "not found"); } if (!string.IsNullOrEmpty(data.NewComment)) { if (!SessionManager.IsUserInSession()) { return(this.Redirect(Utils.Utils.BaseUrl + @"login")); } Model.SaveComment(new Comment() { User_Id = (int)SessionManager.UserId, Text = data.NewComment, Code_Id = code.ID }); return(this.Redirect(Utils.Utils.BaseUrl + @"discussion/" + code.Guid + "#comment_" + Model.Comment_Last_Id(code.ID))); } if (!code.IsOnAWall) { data.Title = "Discussion not available"; } else { data.Title = code.Title; } data.Related = Model.GeRelated(code.ID); data.Votes = code.Votes; data.VoteUp = code.Voted; data.ShowComments = code.IsOnAWall; data.Code = code.Program; data.Date = code.Date; data.Language = code.Lang; data.Comments = Model.GetComments(data.Guid); var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.SafeMode = true; foreach (var c in data.Comments) { c.Text = md.Transform(c.Text); } return(View(data)); }
protected override XElement CreateElement(CmsContext context, CmsPart part) { var md = new MarkdownDeep.Markdown { ExtraMode = true, SafeMode = false, NewWindowForExternalLinks = true, FormatCodeBlock = (markdown, s) => FormatCodeBlock(context, markdown, s) }; return Parse(md.Transform(part.Value)); }
public static string ConvertMdToHtml(this string text) { // Create and setup Markdown translator var md = new MarkdownDeep.Markdown(); md.SafeMode = true; md.ExtraMode = true; // Transform the content and pass to the view return(md.Transform(text)); }
public ActionResult Index() { // View the user editable content // Create and setup Markdown translator var md = new MarkdownDeep.Markdown { SafeMode = true, ExtraMode = true }; // Transform the content and pass to the view ViewBag.Content = md.Transform(m_Content); return View(); }
/// <summary> /// Returns contents of the readme parsed to HTML /// </summary> /// <returns></returns> public string ProvideParsedReadme() { string readmeLocation = Path.Combine(_absoluteRepositoryPath, "README.md"); if (!File.Exists(readmeLocation)) { return(String.Empty); } var md = new MarkdownDeep.Markdown(); return(md.Transform(File.ReadAllText(readmeLocation))); }
public override void Warmup(MarkdownTestSuite suite) { markdown = new MarkdownDeep.Markdown(); var tests = suite.HtmlTests; for (int testNum = 0; testNum < tests.Length; testNum++) { var test = tests[testNum]; var generated = markdown.Transform(test.Text); MarkdownTests.CompareHtml(test.Html, generated); } }
public IContentProvider FillProvider(IContentProvider provider) { var md = new MarkdownDeep.Markdown { ExtraMode = true, SafeMode = false, }; provider.Content = md.Transform(File.ReadAllText(_Path)); return(provider); }
public static string markdown_Transform(this string markdown) { var md = new MarkdownDeep.Markdown { SafeMode = SafeMode, // was false in the MarkdownDeep demo app ExtraMode = ExtraMode, // was true, was creating some probs with HTML conversion (too agreesive on spaces) AutoHeadingIDs = true, MarkdownInHtml = true, NewWindowForExternalLinks = true, }; return md.Transform(markdown); }
/// <summary> /// Converts the markdown text to HTML. /// </summary> /// <param name="preClassName">Optional parameter to insert an HTML class for all 'pre' tags.</param> /// <param name="extraMode">Defaults to false.</param> /// <param name="safeMode">Defaults to true.</param> /// <returns></returns> public static string MarkdownToHtml(this string markdown, string preClassName = "", bool extraMode = false, bool safeMode = true) { var md = new MarkdownDeep.Markdown(); md.ExtraMode = extraMode; md.SafeMode = safeMode; var html = md.Transform(markdown); if (!string.IsNullOrEmpty(preClassName)) html = html.Replace("<pre>", "<pre class=\"" + preClassName + "\">"); return html; }
public static List <PostEntity> GetPagesFromCache(this ICacheService cacheService, IPost postRepository, string keyName, bool isMarkdown) { var markdown = new MarkdownDeep.Markdown { ExtraMode = true }; var pages = cacheService.Get(keyName, () => postRepository.GetPages()); if (isMarkdown) { pages.ForEach(p => p.PostContent = markdown.Transform(p.PostContent)); } return(pages); }
public String ReadAndTransformMarkdownFile(String path) { var md = File.ReadAllText(path); try { var markdown = new MarkdownDeep.Markdown(); return markdown.Transform(md); } catch { return md; } }
} //true; public static string markdown_transform(this string markdown) { var md = new MarkdownDeep.Markdown { SafeMode = SafeMode, // was false in the MarkdownDeep demo app ExtraMode = true, AutoHeadingIDs = true, MarkdownInHtml = true, NewWindowForExternalLinks = true, }; return(md.Transform(markdown)); }
public static string markdown_Transform(this string markdown) { var md = new MarkdownDeep.Markdown { SafeMode = SafeMode, // was false in the MarkdownDeep demo app ExtraMode = ExtraMode, // was true, was creating some probs with HTML conversion (too agreesive on spaces) AutoHeadingIDs = true, MarkdownInHtml = true, NewWindowForExternalLinks = true, }; return(md.Transform(markdown)); }
private async void RenderMarkdown() { if (!string.IsNullOrEmpty(MarkdownFilePath)) // check if MarkdownFilePath is set or not { var m = new MarkdownDeep.Markdown(); // alternative: MarkdownSharp.Markdown(); rest of the syntax is the same string markdown = await Helpers.ReadAllLinesAsync(MarkdownFilePath); _renderedMarkdown = m.Transform(markdown); _html = "<html>\n<head>\n<style>\n"+ _css + "</style>\n</head>\n<body oncontextmenu='return true'>\n" + _renderedMarkdown + "</body>\n</html>"; Viewer.LoadHtml(_html, "http://renderpage/"); _pageLoaded = true; ExportToHTML.IsEnabled = true; } }
public static void RenderMarkdown(this HtmlHelper helper, string filename) { // Load source text var text = System.IO.File.ReadAllText(helper.ViewContext.HttpContext.Server.MapPath(filename)); // Setup processor var md = new MarkdownDeep.Markdown(); md.SafeMode = false; md.ExtraMode = true; md.AutoHeadingIDs = true; md.MarkdownInHtml = true; md.NewWindowForExternalLinks = true; // Write it helper.ViewContext.HttpContext.Response.Write(md.Transform(text)); }
public static AchievementView ConverToAchievementView(this Achievement achievement, int gravatarSize = 40, bool convertMarkdown = false) { var md = new MarkdownDeep.Markdown(); return new AchievementView { Id = achievement.Id, Comment = (convertMarkdown ? md.Transform(achievement.Comment) : achievement.Comment), DateCreated = achievement.DateCreated, UserName = achievement.User.UserName, GravatarUrl = achievement.User.Email.ToGravatarUrl(gravatarSize), Resolution = achievement.Resolution.ToString(), IsOnCourse = achievement.Resolution == Resolution.OnCourse, PrettyDate = achievement.DateCreated.FriendlyParse() }; }
public PagedSet<EventInfo> GetEvents(int skip, int take, bool includeExpired, bool includeRsvpCount, bool includeDeleted) { var posts = _context.Events .Where(w => w.PublishStartTime <= DateTime.Now || w.PublishStartTime == null || includeExpired) .Where(w => w.PublishEndTime >= DateTime.Now || w.PublishEndTime == null || includeExpired) .Where(w => includeDeleted || !w.IsDeleted) .OrderByDescending(o => o.PublishStartTime) .Include(cbu => cbu.CreatedByUser) .Include(g => g.Groups) .Select(s => s); int totalPosts = posts.Count(); var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.SafeMode = false; var mappedPosts = posts.Skip(skip).Take(take).ToList() .Select(s => new EventInfo() { PublishStartTime = s.PublishStartTime, Body = s.Body, HtmlBody = md.Transform(s.Body), HtmlBodySummary = md.Transform(s.Body.Length <= 500 ? s.Body : s.Body.Substring(0, 500).TrimEnd() + "...."), CreatedByUserId = s.CreatedByUserId, CreatedByUserName = GetUserName(s.CreatedByUser), EventEndTime = (s as Event).EventEndTime, EventStartTime = (s as Event).EventStartTime, Id = s.Id, Title = s.Title, GroupTags = s.Groups.Select(g=> g.Id), PublishEndTime = s.PublishEndTime, IsDeleted = s.IsDeleted, AvailableGroups = AvailableGroups, VimeoId = (s as Event).VimeoId, TotalRsvpCount = includeRsvpCount ? _context.Rsvps.Count(w => w.EventId == s.Id): 0 }); return new PagedSet<EventInfo>(totalPosts,skip, take, mappedPosts); }
public String ReadAndTransformMarkdownFile(String path) { var md = File.ReadAllText(path); try { var markdown = new MarkdownDeep.Markdown() { FormatCodeBlock = (mdd, s) => { return "<pre class=\"prettyprint\"><code>" + s + "</code></pre>"; } }; return markdown.Transform(md); } catch { return md; } }
/// <summary> /// Converts the markdown to HTML. /// </summary> /// <param name="toConvert">The markdown string to convert.</param> /// <param name="destinationDocumentPath">The document path (without the document filename).</param> /// <param name="siteRoot">The site root.</param> /// <param name="sourceDocumentFilename">the filename of the source markdown file</param> /// <param name="createdAnchorCollector">The created anchor collector, for ToC sublinks for H2 headers.</param> /// <returns></returns> public static string ConvertMarkdownToHtml(string toConvert, string destinationDocumentPath, string siteRoot, string sourceDocumentFilename, List<Tuple<string, string>> createdAnchorCollector) { var parser = new MarkdownDeep.Markdown { ExtraMode = true, GitHubCodeBlocks = true, AutoHeadingIDs = true, NewWindowForExternalLinks = true, DocNetMode = true, DestinationDocumentLocation = destinationDocumentPath, DocumentRoot = siteRoot, SourceDocumentFilename = sourceDocumentFilename, HtmlClassTitledImages = "figure", }; var toReturn = parser.Transform(toConvert); createdAnchorCollector.AddRange(parser.CreatedH2IdCollector); return toReturn; }
public void Send(string LogMessage, int parentProject, string posterName) { LogEntry newEntry = new LogEntry(); newEntry.Content = LogMessage; newEntry.ParentProject = parentProject; string text = posterName.Replace("WARE", "WARE\\"); newEntry.PostedBy = db.Users.Where(b => b.Username == text).First(); newEntry.PostedOn = DateTime.Now; db.LogEntries.Add(newEntry); db.SaveChanges(); var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.SafeMode = false; string MarkdownOutput = md.Transform(LogMessage); string output = "<div style='display: none;' class='custom-panels panel panel-default'><div class='panel-body' style='margin-bottom: 12px;'>" + MarkdownOutput + "<br /><i class='pull-right' style='font-size: smaller;'>Posted by " + newEntry.PostedBy.FirstName + " " + newEntry.PostedBy.LastName + " on " + newEntry.PostedOn.ToShortDateString() + "</i></div></div>"; Clients.All.send(output, parentProject); }
/// <summary> /// Converts a value. /// </summary> /// <returns> /// A converted value. If the method returns null, the valid null value is used. /// </returns> /// <param name="value">The value produced by the binding source.</param><param name="targetType">The type of the binding target property.</param><param name="parameter">The converter parameter to use.</param><param name="culture">The culture to use in the converter.</param> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { var markdown = value as string; if (markdown != null) { var md = new MarkdownDeep.Markdown(); md.ExtraMode = true; md.NewWindowForExternalLinks = true; md.NewWindowForLocalLinks = true; var body = md.Transform( markdown ); var html = GetHtmlHeader() + body + Properties.Resources.IssueHtmlFooter; return html; } } catch (FormatException e) { _log.Write(LogLevel.Warn, "Failed to create Markdown HTML", e ); } return string.Empty; }