private void KeyboardListener_KeyDown(object sender, KeyEventArgs keyEventArgs) { if (keyEventArgs.Alt && keyEventArgs.Control && keyEventArgs.KeyCode == Keys.M) { var mailItem = Application.ActiveInspector().CurrentItem as Outlook.MailItem; if (mailItem != null) { if (!m_markdownUndo.ContainsKey(mailItem)) { m_markdownUndo.Add(mailItem, null); } // TODO: // * recognize and show warning whenever undo text will clobber changes made by the user // * don't transform user signature and previous messages in the thread // * cleanup old mail items (will hooking into send work?) string bodyTransformed; if (m_markdownUndo[mailItem] != null) { bodyTransformed = m_markdownUndo[mailItem]; m_markdownUndo[mailItem] = null; } else { bodyTransformed = m_markdownProvider.ToHtml(mailItem.Body); m_markdownUndo[mailItem] = mailItem.HTMLBody; } mailItem.HTMLBody = bodyTransformed; keyEventArgs.Handled = true; } } }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { output.TagMode = TagMode.StartTagAndEndTag; output.TagName = "div"; output.Attributes.Add("class", "content"); var content = output.Content.IsModified ? output.Content.GetContent() : (await output.GetChildContentAsync()).GetContent(); output.Content.SetHtmlContent(_markdownService.ToHtml(content)); }
public CommandResult Execute(NewPostCommand command) { //TODO:应该验证TitleSlug是否唯一 var contentProvider = new FileContentProvider(null, Encoding.UTF8); var parser = new MarkdownService(contentProvider); var content = parser.ToHtml(command.MarkDown); var post = new BlogPost { Id = ObjectId.NewObjectId(), AuthorEmail = command.Author.Email, AuthorDisplayName = command.Author.DisplayName, MarkDown = command.MarkDown, Content = content, PubDate = command.PubDate.CloneToUtc(), Status = command.Published ? PublishStatus.Published : PublishStatus.Draft, Title = command.Title, TitleSlug = command.TitleSlug.IsNullOrWhitespace() ? command.Title.Trim().ToSlug() : command.TitleSlug.Trim().ToSlug(), DateUTC = DateTime.UtcNow }; using (var db = new LiteDatabase(_dbConfig.DbPath)) { if (!command.Tags.IsNullOrWhitespace()) { var tags = command.Tags.AsTags(); post.Tags = tags.Keys.ToArray(); var tagCol = db.GetCollection <Tag>(DBTableNames.Tags); foreach (var kv in tags) { var slug = kv.Key; var tag = kv.Value; if (string.IsNullOrWhiteSpace(tag)) { continue; } var entry = tagCol.FindOne(t => t.Slug.Equals(slug)); if (entry != null) { entry.PostCount++; tagCol.Update(entry); } else { entry = new Tag { Id = ObjectId.NewObjectId(), Slug = slug, Name = tag, PostCount = 1 }; tagCol.Insert(entry); } } tagCol.EnsureIndex(t => t.PostCount); } else { post.Tags = new string[] { }; } var blogPostCol = db.GetCollection <BlogPost>(DBTableNames.BlogPosts); blogPostCol.Insert(post); return(CommandResult.SuccessResult); } }
public void Test(string src, string dst) { _markdownService.ToHtml(src).Should().Be(dst); }
public CommandResult Execute(EditPostCommand command) { using (var db = new LiteDatabase(_dbConfig.DbPath)) { var blogPostCol = db.GetCollection <BlogPost>(DBTableNames.BlogPosts); var post = blogPostCol.FindById(command.PostId); if (post == null) { throw new ApplicationException("Post with id: {0} was not found".FormatWith(command.PostId)); } if (post.Tags != null) { var tagCol = db.GetCollection <Tag>(DBTableNames.Tags); foreach (var tag in post.Tags) { var slug = tag.ToSlug(); var tagEntry = tagCol.FindOne(x => x.Slug.Equals(slug)); if (tagEntry != null) { tagEntry.PostCount--; tagCol.Update(tagEntry); } } } var contentProvider = new FileContentProvider(null, Encoding.UTF8); var parser = new MarkdownService(contentProvider); var content = parser.ToHtml(command.MarkDown); //TODO:应该验证TitleSlug是否是除了本文外唯一的 post.MarkDown = command.MarkDown; post.Content = content; post.PubDate = command.PubDate.CloneToUtc(); post.Status = command.Published ? PublishStatus.Published : PublishStatus.Draft; post.Title = command.Title; post.TitleSlug = command.TitleSlug.Trim().ToSlug(); if (!command.Tags.IsNullOrWhitespace()) { var tags = command.Tags.AsTags(); post.Tags = tags.Keys.ToArray(); var tagCol = db.GetCollection <Tag>(DBTableNames.Tags); foreach (var kv in tags) { var slug = kv.Key; var tag = kv.Value; var entry = tagCol.FindOne(x => x.Slug.Equals(slug)); if (entry != null) { entry.PostCount++; tagCol.Update(entry); } else { entry = new Tag { Id = ObjectId.NewObjectId(), Slug = slug, Name = tag, PostCount = 1 }; tagCol.Insert(entry); } } } else { post.Tags = new string[] { }; } db.GetCollection <BlogPost>(DBTableNames.BlogPosts).Update(post); return(CommandResult.SuccessResult); } }